Author |
Message |
12/11/2019 08:21:31
|
rchiluano
Power User
Joined: 28/12/2017 07:21:54
Messages: 79
Offline
|
Hi captain,
I am using formattedfield to get the time from my db
which specifically 1521-01-01 13:01:00.
Now I want to get the time by HH:mm which is 13:01.
Unfortunately, I got the wrong data.
It displays 13:06 (it added 5) instead.
Is this some kind of bug or did I miss something? like attribute or ...?
Regards,
Ryan
|
|
|
12/11/2019 08:46:12
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5521
Offline
|
??? Not possible! ;-)
We just tested:
Code:
<t:rowbodypane id="g_ccpreview_4" >
<t:row id="g_ccpreview_5" >
<t:formattedfield id="g_ccpreview_6" format="time" timezone="GMT" value="-14169034740000" width="120" />
</t:row>
</t:rowbodypane>
Works perrrrfectly.
Could you provide an isolated example? Thanks!
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
12/11/2019 08:59:08
|
rchiluano
Power User
Joined: 28/12/2017 07:21:54
Messages: 79
Offline
|
XML Code :
Code:
<t:formattedfield id="g_5" format="time" formatmask="HH:mm" value="#{d.TestPage.timeTest}" width="100" />
Java Code :
setTimeTest(result.getTime("Document_Date"));
Database Data :
1800-01-01 13:01:00
Result :
13:06
|
|
|
12/11/2019 09:32:02
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5521
Offline
|
What is the long value of getTimeTest()?
Just add a FORMATTEDFIELD with FORMAT "long" to the test page...
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
12/11/2019 10:01:57
|
rchiluano
Power User
Joined: 28/12/2017 07:21:54
Messages: 79
Offline
|
Hi captain,
This is the long value "-5364644340000"
The expected result must be 13:01 instead of 13:06
And also,
Printing the getTimeTest(); in console shows the correct value(13:01). But the component, shows 13:06.
Regards,
Ryan
|
|
|
12/11/2019 10:27:54
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5521
Offline
|
Ha,
I can reproduce! The difference is that I am always applying a TIMEZONE (which is mandatory)... I am just evaluating...
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
12/11/2019 10:40:21
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5521
Offline
|
Wow... JavaScript calculates "old" days in a weird way.
I attached the debugging image: it's JavaScript which calculates the date into some "GMT+53" timezone for "old" days. This does not happend for dates in the area > 1900.
The situation is bypassed when defining the timezone.
PAYING ATTENTTION to the time zone is "1000% important" anyway. We added some own chapter to the Developer's Guide on this some weeks ago!
Conclusion: please pass a timezone - and also check your application in general on date treatment.
Regards, Björn
|
Filename |
datejavascript.png |
Download
|
Description |
|
Filesize |
8 Kbytes
|
Downloaded: |
362 time(s) |
|
Björn Müller, CaptainCasa GmbH |
|
|
12/11/2019 11:22:17
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5521
Offline
|
btw - I posted this at stackoverflow...: https://stackoverflow.com/questions/58817774/weird-javascript-timezone-for-early-days-e-g-01-01-1800
Let's see if someone has some good answer.
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
12/11/2019 11:39:35
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5521
Offline
|
...and there was a quick answer: which basically says - do not use "early" dates when directly accessing JavaScript dates...
So, there are two options for you...: shift your time calculation in some "up to date" date area.
Or/and: MUCH BETTER - set the TIMEZONE because then dates are calculated using the moment.js library which does this more carefully than the browser.
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
13/11/2019 05:23:54
|
rchiluano
Power User
Joined: 28/12/2017 07:21:54
Messages: 79
Offline
|
Hi captain,
Seems setting the timezone still does not solve the problem.
|
|
|
13/11/2019 05:33:06
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5521
Offline
|
Which timezone do you set? - Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
13/11/2019 05:44:24
|
rchiluano
Power User
Joined: 28/12/2017 07:21:54
Messages: 79
Offline
|
GMT+8
|
|
|
13/11/2019 05:49:19
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5521
Offline
|
Is this the name of the timezone? I would expect something like "GMT","CET","UTC" - see https://www.timeanddate.com/time/zones/
If you run in your server side Java the following...
Code:
TimeZone.getDefault().getID()
What's the result?
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
13/11/2019 05:56:03
|
rchiluano
Power User
Joined: 28/12/2017 07:21:54
Messages: 79
Offline
|
My bad.
This is the timezone
PHT
and this is the result:
Asia/Shanghai
of this code:
Code:
TimeZone.getDefault().getID()
|
|
|
13/11/2019 06:10:01
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5521
Offline
|
PHT is not supported in moment js...
But "Asia/Shanghai" is supported! ;-)
I will provide a list of time zones later on during today which are supported by moment.js.
(https://stackoverflow.com/questions/21348404/how-do-i-get-timezones-list-using-moment-js-library)
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
|