0

Date is changed on the datebox after the user's input

asked 2016-10-24 10:06:02 +0800

eclipse1 gravatar image eclipse1
21 4

updated 2016-10-24 10:14:46 +0800

We are having a problem with our dateboxes. If the user chooses the 01-01-1970 on a datebox, after the component looses focus the date being shown is 31-12-1969.

We have a prefered timezone and then some of our pages have a specific timezone. The user should input the date according with the page's timezone and the date is converted to milliseconds with the timezone UTC. These are the configurations we have for the timezones used in the components:

  • Time zone at zk.xml: UTC
  • Time zone at the component language addon: UTC
  • Time zone set at the component usage inside the zul file: Europe/Lisbon

Our expectations were that the timezone defined at the ZUL (Europe/Lisbon) overrides the other definitions, however the result is not consistent.

We created the next class to show us the expected time in milliseconds for the dates.

package dateCalculation;

import java.util.Calendar;
import java.util.TimeZone;

public class EuropeLisbonDateGenerator {

                public static void main(String[] args) {
                                printLisbonDatesSince1970();
                }

                private static void printLisbonDatesSince1970() {
                                Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Europe/Lisbon"));
                                calendar.set(Calendar.DAY_OF_MONTH, 1);
                                calendar.set(Calendar.HOUR_OF_DAY,0);
                                calendar.set(Calendar.MINUTE, 0);
                                calendar.set(Calendar.SECOND, 0);
                                calendar.set(Calendar.MILLISECOND, 0);

                                for(int year = 1970; year < 2017; year++) {
                                                calendar.set(Calendar.YEAR, year);
                                                calendar.set(Calendar.MONTH, Calendar.JANUARY);
                                                System.out.println("1 January " + year + ": " + calendar.getTimeInMillis());
                                                calendar.set(Calendar.YEAR, year);
                                                calendar.set(Calendar.MONTH, Calendar.JULY);
                                                System.out.println("1 July " + year + ": " + calendar.getTimeInMillis());
                                }
                }

}

This were the results:

Inputed value: 01-01-1970 (dd-mm-yyyy). The actual date in millis inside the custom converter: 0 (not ok). The expected date in millis inside the custom converter: -3600000

Inputed value: 01-07-1970 (dd-mm-yyyy). The actual date in millis inside the custom converter: 15638400000 (ok). The expected date in millis inside the custom converter: 15638400000

Inputed value: 01-01-2016 (dd-mm-yyyy). The actual date in millis inside the custom converter: 1451606400000 (ok). The expected date in millis inside the custom converter: 1451606400000

Inputed value: 01-07-2016 (dd-mm-yyyy). The actual date in millis inside the custom converter: 1467327600000 (ok). The expected date in millis inside the custom converter: 1467327600000

Do you know how to fix this problem?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-10-30 09:06:18 +0800

Darksu gravatar image Darksu
1991 1 4

Hello eclipse1,

Solution may be quite simple. Just add a constraint for the date value to be after 01-01-1970.

Check section constraints:

https://www.zkoss.org/wiki/ZKComponentReference/Input/Datebox

Best Regards,

Darksu

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2016-10-24 10:06:02 +0800

Seen: 44 times

Last updated: Oct 30 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More