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

startOf('day') is giving me yesterday #3086

Closed
M-Zuber opened this issue Apr 3, 2016 · 3 comments
Closed

startOf('day') is giving me yesterday #3086

M-Zuber opened this issue Apr 3, 2016 · 3 comments

Comments

@M-Zuber
Copy link

M-Zuber commented Apr 3, 2016

Running the following code in Chrome Version 49.0.2623.110 m
image
Maybe related to #2982 ?

@maggiepint
Copy link
Member

Because you are using the moment() function to construct your date, moment assumes you are handling a local date. Thus, the .startOf() function is moving you to the start of your local date.
.toISOString() though, outputs a UTC date, as indicated by the Z at the end of the strings.

Based on your github profile, it appears you are in Israel. So, adjusting for the Asia/Jerusalem timezone and putting it all in code:

//the time now in Jerusalem
moment().format()
"2016-04-03T14:48:10+03:00"

//start of day in Jersualem
moment().startOf('day').format()
"2016-04-03T00:00:00+03:00"

//start of day as ISO string is three hours before start of day in Jerusalem
moment().startOf('day').toISOString()
"2016-04-02T21:00:00.000Z"

You either need to work completely in local time, and use .format() to get the result you want, or work completely in UTC.

This section of the docs might be helpful:
http://momentjs.com/guides/#/parsing/local-utc-zone/

@M-Zuber
Copy link
Author

M-Zuber commented Apr 3, 2016

:face-palm:

Thank you for the thorough explanation.

@maggiepint
Copy link
Member

I think I've actually explained this one at least twice this week between here and Stack Overflow. You're not the only person to be confused. I'm going to update the docs to make the UTC part a bit more clear.

maradragan added a commit to NCI-Agency/anet that referenced this issue Nov 9, 2018
The date widget in the advanced search was displaying a day earlier than
the day it should have. Here is why:
moment/moment#3086
maradragan added a commit to NCI-Agency/anet that referenced this issue Nov 9, 2018
The date widget in the advanced search was displaying a day earlier than
the day it should have. Here is why:
moment/moment#3086
maradragan added a commit to NCI-Agency/anet that referenced this issue Nov 12, 2018
The date widget in the advanced search was displaying a day earlier than
the day it should have. Here is why:
moment/moment#3086
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

No branches or pull requests

2 participants