JFXtras / jfxtras

A supporting library for JavaFX, containing helper classes, extended layouts, controls and other interesting widgets.
http://jfxtras.org
Other
599 stars 123 forks source link

Error setting calendar for CalendarPicker #106

Closed moctavianro closed 3 years ago

moctavianro commented 5 years ago

If i set a UTC Calendar set to 0 hours, minutes and seconds to CalendarPicker, the clock will start from 2 instead 0.

tbee commented 5 years ago

Show me some code. :-)

moctavianro commented 5 years ago

Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.US); calendar.setTimeInMillis(DateTimeDialog.getInstance().getTimeToSet()); mCalendarPicker.setCalendar(calendar);

moctavianro commented 5 years ago

capture capture2

moctavianro commented 5 years ago

thanks 4 help dude

tbee commented 5 years ago

You are setting a time in the calendar in the second line, no idea what value that is.

But, CalendarPicker is not doing anything with time zones, it uses merely a locale to get the day names right. It just renders the day, month, year, hour, minute, seconds that are in the calendar. Very curious what this line inserted before the setCalendar gives as a result:

System.out.println(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(calendar.getTime()));

moctavianro commented 5 years ago

as u can see in the photos above, the clock starts from 2 and ends to 1:59. That seems a bug to me since it must start from 0 and end to 23:59

tbee commented 5 years ago

ohhhh, I see!

moctavianro commented 5 years ago

It happens when i switch the calendar from default to UTC and set it to CalendarPicker.

tbee commented 5 years ago

Indeed. Interesting. I can reproduce it now.

moctavianro commented 5 years ago

so when i should expect a patch? :))

tbee commented 5 years ago

This is open source, so never :-) But I am looking into it now

tbee commented 5 years ago

So the cause is in calendar, but I have to think about why. If you execute this code:

    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.US);
    System.out.println("H1=" + calendar.get(Calendar.HOUR_OF_DAY) + " / " + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(calendar.getTime()));
    Calendar calendar2 = Calendar.getInstance();
    System.out.println("H2=" + calendar2.get(Calendar.HOUR_OF_DAY) + " / " + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(calendar2.getTime()));

I get this output (its just after noon here):

    H1=11 / 2018-12-28T12:14:45.468
    H2=12 / 2018-12-28T12:14:45.476

What you see if that they format into the same time (12 o'clock), but if you query for the 24-hour value, they differ.

moctavianro commented 5 years ago

that s strange indeed. I figured a workaround for me, i get the default time in millis then i extract the timezone raw offset, It works.

tbee commented 5 years ago

The formatter uses Date, which is not timezone aware, and thus always renders in the current timezone. The hour of day returns the value in the current timezone. Have to thing about how to solve this best, because date and time picking is done timezone unaware.

tbee commented 5 years ago

I think I have fixed it, but the release needs to pass all tests first. It is a fairly large change.

moctavianro commented 5 years ago

i see

tbee commented 5 years ago

I assume you're still using Java 8? Give 8-r7-SNAPSHOT a try please