[Logo] Enterprise Client Community
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
formattedfield time format not working on 1521-01-01  XML
Forum Index -> Development Go to Page: 1, 2 Next 
Author Message
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
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
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
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
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
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
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
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
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
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
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
[Thumb - datejavascript.png]
 Filename datejavascript.png [Disk] Download
 Description
 Filesize 8 Kbytes
 Downloaded:  358 time(s)


Björn Müller, CaptainCasa GmbH
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
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
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
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
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.

CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
Offline

Which timezone do you set? - Björn

Björn Müller, CaptainCasa GmbH
rchiluano

Power User

Joined: 28/12/2017 07:21:54
Messages: 79
Offline

GMT+8
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
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
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()



CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
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
 
Forum Index -> Development Go to Page: 1, 2 Next 
Go to:   
Powered by JForum 2.1.6 © JForum Team