Titanium JIRA Archive
Appcelerator Community (AC)

[AC-460] Windows: MomentJS startOf() and endOf() functions seem to report the wrong date

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionNot Our Bug
Resolution Date2015-12-03T09:26:50.000+0000
Affected Version/sAppcelerator Studio 4.3.0
Fix Version/sn/a
ComponentsAlloy, Titanium SDK & CLI
Labelsalloy, moment, windows
ReporterByron Davies
AssigneeMostafizur Rahman
Created2015-10-12T16:01:26.000+0000
Updated2015-12-03T09:52:41.000+0000

Description

I'm porting an app from iOS/Android to Windows Phone. It's a scheduling app that relies heavily on the momentjs library to manage and compare dates. I have noticed that the moment startOf and endOf functions are reporting the wrong dates, they are out by a number of days, not just hours. I have included a sample index.js file from a clean project, the output from this when I run it is: [INFO] : today string = Mon Oct 12 2015 16:48:38 GMT+0100 [INFO] : startOfToday string = Thu Oct 08 2015 00:00:00 GMT-2300 [INFO] : startOfToday unix = 1444345200 [INFO] : endOfToday string = Thu Oct 08 2015 23:59:59 GMT+0100 [INFO] : endOfToday unix = 1444345199 As you can see, the current date is Oct 12th, but the startOf('day') and endOf('day') functions are way out. I have tried it in a browser on my machine and they all check out, so I can only think it is an issue with the JS runtime.

Attachments

FileDateSize
index.js2015-10-12T16:01:01.000+0000498

Comments

  1. Byron Davies 2015-10-20

    I've done some further investigation and I think that there is an issue with the Javascript Date() object within (presumably) the JSCore for Windows. This can be highlighted if you run the following: var plainDate = new Date(); console.log('plainDate string = ' + plainDate); plainDate.setHours(23); plainDate.setMinutes(0); plainDate.setSeconds(0); plainDate.setMilliseconds(0); console.log('plainDate endOfDay = ' + plainDate); The Ti console will show: [INFO] : plainDate string = Tue Oct 20 2015 21:25:48 GMT+0100 (GMT Summer Time) [INFO] : plainDate endOfDay = Sat Oct 24 2015 23:00:00 GMT+0100 (GMT Summer Time) If you change 'setHours' to 22 you don't get this issue. I believe therefore that this is an issue with the day not rolling over properly due to Daylight Savings Time (currently we are 1 hour ahead). You seem to get an extra day added to the 'plainDate' object each time you modify it. Moment is backed by this Date object and the various date functions, and therefore it is completely unreliable.
  2. Fokke Zandbergen 2015-10-22

    Not the first time Windows is having issues with dates: TIMOB-18855
  3. Byron Davies 2015-10-22

    In order to move forward I was temporarily looking to use the JS runtime in a WebView and use evalJS() to get around this (hacky I know), but I don't think it is implemented. My project is effectively dead in the water until this is fixed as it relies heavily on dates and date manipulation.
  4. Byron Davies 2015-11-13

    Just an update, now we have left Daylight savings time, the issue seems to have fixed itself for me. This'll of course rear it's head again in 6 months.....
  5. Byron Davies 2015-12-03

    Hi there, It's been marked as 'Not Our Bug'. Is there a bit more explanation on this? Where is the bug? Who's responsibility is it to fix? Have any support tickets been raised, etc... Thanks

JSON Source