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

Fix bugs with parsing to and from timezones #7

Merged
merged 3 commits into from
Feb 13, 2017
Merged

Conversation

shepherdsam
Copy link
Contributor

No description provided.

Split handling of parsed and moment return values
Improved tests: Verify the results of the parsed dates.
lib/index.js Outdated
});
var tz = moment.tz.guess() || 'UTC';
Utils.Logger.warn('Utils.parseDateTimeField - Timezone "' + timezone + '" is invalid. Assuming ' + tz);
timezone = tz;
Copy link
Contributor

Choose a reason for hiding this comment

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

We're changing timezone here but the options.locale was already decided above, with the old timezone. Does line 445 need to be moved to below this if block to take the new timezone into account?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good catch!

lib/index.js Outdated
var parsedDateWithTimezone = parseDateTime(field, options, timezone);
if (SugarDate.isValid(parsedDateWithTimezone)) {
Utils.Logger.debug('Utils.parseDateTimeField: parsedDateWithTimezone:', parsedDateWithTimezone.toISOString());

var hasTZOffset = new RegExp('[+-]{1}[0-9]{2}:?[0-9]{2}').test(field);
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this wasn't part of the changes but maybe this regex could be tightened up? How about:

/(?:[zZ]|[+-][01]\d:[0-5]\d)$/.test(field)

This takes into account:

  • a UTC Z timezone offset
  • the fact that +99:99 isn't a valid timezone offset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I ended up with.

/[zZ]|[+-][01]\d:?[0-5]\d/

I removed the $ to allow for dates with our custom offset. 2013-02-08 09:30+07:00 +1d - 12h.

@shepherdsam shepherdsam merged commit 1eaaa1a into master Feb 13, 2017
@shepherdsam shepherdsam deleted the fix/timezone branch February 22, 2017 19:46
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.

2 participants