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

Leverage setHours to have a more efficient implementation of start-end-of #3619

Closed
aymericbouzy opened this issue Nov 23, 2016 · 2 comments
Closed

Comments

@aymericbouzy
Copy link

aymericbouzy commented Nov 23, 2016

Description of the Issue and Steps to Reproduce:

let d = new Date()
d.setHours(0, 0, 0, 0)

is way more efficient than :

let d = new Date()
d.setHours(0)
d.setMinutes(0)
d.setSeconds(0)
d.setMilliseconds(0)

(about 400 times faster)

When calling startOf(unit), where unit is one of 'hour', 'day', 'week', 'month', 'year', moment should use the first method rather than the second one.

Environment:

I'm running a ReactNative app on an iOS Simulator, running iOS 10.1.

Other information that may be helpful:

  • The time zone setting of the machine the code is running on : UTC + 01:00 (Paris, France)
  • The time and date at which the code was run : 2016-11-23T10:56:19+01:00
  • Other libraries in use (TypeScript, Immutable.js, etc) : ReactNative
console.log( (new Date()).toString())
// [Log] Wed Nov 23 2016 10:58:47 GMT+0100 (CET) (index.ios.bundle, line 788)
console.log((new Date()).toLocaleString())
// [Log] 11/23/2016, 10:58:47 AM (index.ios.bundle, line 788)
console.log( (new Date()).getTimezoneOffset())
// [Log] -60 (index.ios.bundle, line 788)
console.log( navigator.userAgent)
// [Log] undefined (index.ios.bundle, line 788)
console.log(moment.version)
// [Log] 2.14.1 (index.ios.bundle, line 788)
@aymericbouzy
Copy link
Author

#3620

@maggiepint
Copy link
Member

closed in favor of #3620

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants