Upload
adam-hodowany
View
438
Download
0
Embed Size (px)
Citation preview
https://en.wikipedia.org/?title=Time_zone#/media/File:World_Time_Zones_Map.png
Daylight Saving Time Explained by CGP Grey
https://youtu.be/84aWtseb2-4
<select>
Time Zone != Offset
UTC - time standard GMT - time zone
(since 1972)
Date formats
Best case scenario - ISO 8601
offset
2015-06-25T07:38:12+00:00
2015-06-25T07:38:12+0000
2015-06-25T07:38:12+04:30
2015-06-25T07:38:12-01:00
2015-06-25T07:38:12-04
2015-06-25T07:38:12Z
2015-06-25T07:38:12ZZulu time == UTC
Other formats
2018-10-06T23:21:00+01:00
My system’s offset: +2
date = '2018-10-06T23:21:00+01:00'
$filter('date')(date, 'dd-MM-yyyy')=> 07-10-2018
moment(date).format('DD-MM-YYYY')=> 07-10-2018
new Date(date).toString()=> Sun Oct 07 2018 00:21:00 GMT+0200 (CEST)
date = '2018-10-06T23:21:00'
$filter('date')(date, 'dd-MM-yyyy')=> 06-10-2018
moment(date).format('DD-MM-YYYY')=> 06-10-2018
new Date(date).toString()=> Sun Oct 07 2018 01:21:00 GMT+0200 (CEST)
date = '2018-10-06'
$filter('date')(date, 'dd-MM-yyyy')=> 06-10-2018
moment(date).format('DD-MM-YYYY')=> 06-10-2018
new Date(date).toString()=> Sat Oct 06 2018 02:00:00 GMT+0200 (CEST)
date = '2018-10-06'
$filter('date')(date, 'dd-MM-yyyy')=> 06-10-2018
moment(date).format('DD-MM-YYYY')=> 06-10-2018
new Date(date).toString()=> Fri Oct 05 2018 21:00:00 GMT-0300 (BRT)
My system’s offset now: -3
WHAT IF
We’d like to show date and time in user’s time zone that doesn’t equal her operating system’s time zone?
AngularJS
AngularJS
angular.module('project').filter('myDate', function($filter, User) { return function(input) { return $filter('date')(input, 'dd-MM-yyyy', User.current.timezone_offset); };});
How to get offset?
1. It’s back-end problemtz = ActiveSupport::TimeZone.new("Europe/Warsaw")
tz.utc_offset=> 3600 # offset in seconds: +1 hour even thoughcurrently it’s DST and it should be +2
tz.now.dst? # now -> passing the context=> true
tz.at(6.months.ago).dst?=> false
tz.now.utc_offset=> 7200
2. It’s front-end problem
jmp momenttimezone
Moment Timezone
moment('2018-10-06T23:21:00+01:00') .tz('America/Los_Angeles') .format()=> 2018-10-06T15:21:00-07:00
moment.tz .setDefault('America/Los_Angeles')
moment('2018-10-06T23:21:00+01:00') .format()=> 2018-10-06T15:21:00-07:00
Possible problem?
'America/Los_Angeles'
Rails match this format:
https://github.com/rails/rails/blob/a0a6e0292f66b546a3aee6893136a89bfd10579c/activesupport/lib/active_support/values/time_zone.rb#L43
Thank youQuestions?