Java2Dart Date

 A common pitfall when working with dates in software is the DST (Daylight saving time).


For example the following code just adds 24hrs:

	for (int i = 0; i < 365; i++) {
			date = new Date(date.getTime() + 24 * 60 * 60 * 1000);
			System.out.println(date);
		}



The result will show confusing behavior when DST occurs.



Wed Mar 28 00:00:00 IST 2012
Thu Mar 29 00:00:00 IST 2012

Fri Mar 30
00:00:00 IST 2012
Sat Mar 31 01:00:00 IDT 2012

Sun Apr 01 01:00:00 IDT 2012


The right way to increment a single day in java is:

 

 

Calendar c = Calendar.getInstance();
for (int i = 0; i < 365; i++) {
        c.add(Calendat.DATE,1);
 	System.out.println(c.getTime());
}

The result will be when DST occurs:
Thu Mar 29 00:00:00 IST 2012
Fri Mar 30 00:00:00 IST 2012
Sat Mar 31 00:00:00 IDT 2012

Sun Apr 01 00:00:00 IDT 2012
Mon Apr 02 00:00:00 IDT 2012
Tue Apr 03 00:00:00 IDT 2012
Wed Apr 04 00:00:00 IDT 2012


Now its time to see how Google dart is doing this :


  Date date = new  Date(2012,  1,  1,  0,  0,  0,       0);
  for (int i = 0; i < 365 ; i++){
  date. add(const new Duration(days:1));
   print(date);
  }



The result when DST occurs:
2012-03-29 00:00:00.000
2012-03-30 00:00:00.000
2012-03-31 01:00:00.000

2012-04-01 01:00:00.000
2012-04-02 01:00:00.000

Opps...
It seems that DART still a long road ahead, in order to support proper scheduling.

 

Thank you for your interest!

We will contact you as soon as possible.

Want to Know More?

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com
Thank you for your interest!

We will contact you as soon as possible.

Let's talk

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com