Date and Time formatting not all the time correct


#1

It just occured that the date and time formatting seems to be a little off. It could also be me :slight_smile: Not 100% sure and if this is right, is there a way to fix this. Here is the scenario.

I’m trying to convert UTC time (from ISO 8601 format) using addHours. What i found was that webcore seems to be handling the date and time differently, depending on the time. Here is 2 test i did. One where the UTC time is past 12:00:00 and another one before that. When it goes past 12:00:00 that is when things go out of place.

This shows things working normally, where after converting and adding hours, the time is correct:-



Here is the one where it goes off by a day.



From what i can see, the error in time only pop’s in when the time(before conversion is from 12:00:00 to 23:59:59. Outside those times, the conversion doesn’t seem right.

I hope all this makes sense.


#2

Can you explain the problem? 11 hours after 9 pm on the 2nd is 8am on the 3rd.

I see that your second moreTesting screenshot shows November 2 rather than November 1 from the previous screenshot. Is that the error, or was the value of estimate changed between those two screenshots?


#3

Sure thing. For the “moreTesting” screens, the UTC time is 9:06PM on the 1st of November. When i apply formatDateTime to it, it seems to add a day to the time - this is without adding any hours, and this resulted with the output of 9:06PM on the 2nd of November, rather than the 1st of November at 9:06PM.

However, for the ‘anotherTest’ screens, the UTC time is 12:35AM on the 2nd of November. Using the formatDateTime worked correctly and translated to the desired format correctly.

I guess, there is nothing wrong with the addHours…i should not have added that in as it can confuse thing. The “bug” that i am seeing is the formatting of the date and time when using formatDateTime. If i remember correctly i had the same problems when using ‘datetime’ function as well.

I ran this over the course of 2 days and what i noticed was that if the UTC time was after 12:00:00, the additional day is then added. Before 12:00:00 seems to be a-ok.


#4

Thanks i understand now, that looked like it could have been the problem you identified. I’ll see if I can set my hub in that time zone to test the formatting.


#5

I actually got the UTC with ISO format from a web response. The response was in UTC and my timezone is GMT+11, that was why the last screen i used the addHours :slight_smile:


#6

I could not find a way to change my hub’s timezone but I think the problem is that among all the manipulation webCoRE has to do to try to make sense of dates with Groovy’s very poor date handling there is just no support for the ISO 8601 date format. I think what you are actually seeing here is the time portion working as expected but the date portion mapping to today’s date. I tried the same format with October 10 and it still yields November 3.


#7

That was what i was thinking. I thought i’d just put it out there. Anyway, to ‘artificially’ fix it i used

$hour24 > 11 ? ‘11’ : ‘-13’

That so far seems to be working.

Thanks anyway for having a look.