Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #353: Date Ranges should honour timezone settings. #370

Merged
merged 4 commits into from
Mar 28, 2014
Merged

Issue #353: Date Ranges should honour timezone settings. #370

merged 4 commits into from
Mar 28, 2014

Conversation

lukecarbis
Copy link
Contributor

The problem here is that the date picker uses the date of the visitor’s
computer. This means that we have to take the site GMT offset, and add
the local computer’s GMT offset, and then compare the current date with
the offset date.

Resolves #353

The problem here is that the date picker uses the date of the visitor’s
computer. This means that we have to take the site GMT offset, and add
the local computer’s GMT offset, and then compare the current date with
the offset date.
@@ -171,6 +171,7 @@ public static function admin_enqueue_scripts( $hook ) {
'confirm_purge' => __( 'Are you sure you want to delete all Stream activity records from the database? This cannot be undone.', 'stream' ),
'confirm_uninstall' => __( 'Are you sure you want to uninstall and deactivate Stream? This will delete all Stream tables from the database and cannot be undone.', 'stream' ),
),
'gmt_offset' => get_option('gmt_offset'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukecarbis Travis is failing due to lack of spacing in this line: get_option( 'gmt_offset' )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#OMGBBQ 😉

@frankiejarrett
Copy link
Contributor

@lukecarbis Unfortunately, this PR isn't quite working for me yet.

  1. I spoof my local env time to be 8pm (which equals 1am GMT since I am -0500).
  2. I double check in Settings > General that my local time and GMT are in fact different dates (3/27 vs. 3/28).
  3. I clear my browser cache by testing in incognito mode to ensure the latest JS is being used.
  4. I select "Today" from the predefined date list and it puts 2014/03/28 into the date fields instead of 2014/03/27.

@c3mdigital
Copy link

@fjarrett @lukecarbis I had this same javascript offset problem on some scheduling feature I worked on. I'm adding the code I had to use to get it working right in case it might help here.

getRegionTime: function () {
            var date = new Date(), UTC = date.getTime() + (date.getTimezoneOffset() * 60000);
            return new Date(UTC + (3600000 * Ajax_Schedules.getOffset()));
        },

This relied on the getOffset method which just converted the users timezone to + - hours from UTC then checking if it's daylight savings using this function and adding the extra hour if true.

        is_dst: function () {
            Date.prototype.stdTimezoneOffset = function () {
                var jan = new Date(this.getFullYear(), 0, 1);
                var jul = new Date(this.getFullYear(), 6, 1);
                return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
            };
            Date.prototype.dst = function () {
                return this.getTimezoneOffset() < this.stdTimezoneOffset();
            };
            var today = new Date();
            return today.dst();
        },

Another function that used some of the built in datepicker methods:

        showLocalTime: function () {
            var time_div = $('.local-time'), date = Ajax_Schedules.getRegionTime(), sp = ' ',
                hour = 12 < date.getHours() ? date.getHours() - 12 : date.getHours(),
                _hour = (0 === hour) ? 12 : hour, format = 'D M d yy',
                minute = date.getMinutes() + '',
                _minute = (1 === minute.length) ? '0' + minute : minute,
                _time = $.datepicker.formatDate(format, date).toUpperCase() + ' at ' + _hour + ':' + _minute;

            time_div.html( '<time datetime="' + $.datepicker.formatDate('yy-mm-dd', date) + '" class="txt-regular right">' + _time + '</time>');
        },

@lukecarbis
Copy link
Contributor Author

@c3mdigital Thanks!

@fjarrett Good pickup. I hadn't thought to test the dropdown menu, I was only looking at the datepicker fields.

@frankiejarrett
Copy link
Contributor

@lukecarbis When I select Yesterday from the dropdown the start date is correct, but the end date is incorrect.

screen shot 2014-03-27 at 8 09 06 pm

@lukecarbis
Copy link
Contributor Author

Okay - I've found a better way of implementing timezone support in carbon. I had to get the wordpress timezone string (e.g. Australia/Brisbane) but if it didn't exist (e.g. GMT +10), then I had to search for the string based on the offset.

frankiejarrett added a commit that referenced this pull request Mar 28, 2014
Issue #353: Date Ranges should honour timezone settings.
@frankiejarrett frankiejarrett merged commit e74592f into xwp:develop Mar 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Date ranges should honor the site timezone setting
4 participants