-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
moment-timezone compatability for DateInput #297
moment-timezone compatability for DateInput #297
Conversation
Thanks for your interest in palantir/blueprint, @mfedderly! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
@@ -320,4 +321,36 @@ export class DateInput extends AbstractComponent<IDateInputProps, IDateInputStat | |||
private setInputRef = (el: HTMLElement) => { | |||
this.inputRef = el; | |||
} | |||
|
|||
/** | |||
* Translate a moment into a Date object, adjusting the moment timezone into the local one. |
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.
where does the adjustment happen? i'm assuming it's inside moment but it's not obvious why this works.
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.
Date objects are always in the local timezone. Moment operates in the specified timezone after moment.tz.setDefault has been called (or the local timezone if none has been configured). Therefore directly copying the individual components of the dates corrects for the timezone discrepancy.
* Translate a moment into a Date object, adjusting the moment timezone into the local one. | ||
* This is a no-op unless moment-timezone's setDefault has been called. | ||
*/ | ||
private fromMomentToDate = (date: moment.Moment) => { |
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.
a different name would be helpful to clarify that this is not a Date
. momentDate
?
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.
Sounds good.
thanks @mfedderly! |
Fixes #280
Changes proposed in this pull request:
Reviewers should focus on: