JFXtras / jfxtras

A supporting library for JavaFX, containing helper classes, extended layouts, controls and other interesting widgets.

Home Page:http://jfxtras.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error setting calendar for CalendarPicker

moctavianro opened this issue · comments

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

Show me some code. :-)

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

thanks 4 help dude

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()));

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

ohhhh, I see!

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

Indeed. Interesting. I can reproduce it now.

so when i should expect a patch? :))

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

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.

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.

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.

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

i see

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