-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
No description provided.