About Question enthuware.ocpjp.v8.2.1750 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ramlax
Posts: 3
Joined: Sat May 28, 2016 2:10 am
Contact:

About Question enthuware.ocpjp.v8.2.1750 :

Post by ramlax »

So the question is:
"Given that daylight Savings Time starts on March 8th at 2 AM in US/Eastern time zone. (As a result, 2 AM becomes 3 AM.)"

Here we have March/08 02:00AM it means you have 03:00.
Here we have March/08 03:00AM it means you have 03:00.

Can someone explain to me why is the result of ChronoUnit.HOURS.between function here 0, considering the analogy in the
from the question viewtopic.php?f=2&t=3659?

Apparently the time in DST start (March) is moved ahead to 3 AM in contrast with DST end time (November) which is not moved back to 1 AM, or I misunderstood something?

Code: Select all

LocalDateTime ld1 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0);    // 2015-11-01T02:00
ZonedDateTime zd1 = ZonedDateTime.of(ld1, ZoneId.of("US/Eastern"));     // 2015-11-01T02:00-05:00[US/Eastern
LocalDateTime lod1 = LocalDateTime.of(2015, Month.MARCH, 8, 2, 0);       // 2015-03-08T02:00
ZonedDateTime zod1 = ZonedDateTime.of(lod1, ZoneId.of("US/Eastern")); // 2015-03-08T03:00-04:00[US/Eastern] 
Thank you for your help.
Last edited by admin on Sun May 29, 2016 12:12 am, edited 1 time in total.
Reason: Fixed the link

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1750 :

Post by admin »

It is the same logic. How many hours do you need to add to reach 3AM from 2AM. Usually, 1. But on this particular day, you need to add 0 hours.
If you like our products and services, please help us by posting your review here.

ramlax
Posts: 3
Joined: Sat May 28, 2016 2:10 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1750 :

Post by ramlax »

Apparently my question was not precise. Let's forget about this concrete exercise at all.

I just want to understand the following logic.
2015 ---> Sun, 8 Mar, 02:00 --- EST → EDT +1 hour (DST start)
2015 ---> Sun, 1 Nov, 02:00 --- EDT → EST -1 hour (DST end)

Let the first example be DST start, at 2:00 the time is changed for +1 hour. This is quite easy to understand.

Code: Select all

LocalDateTime lod1 = LocalDateTime.of(2015, Month.MARCH, 8, 2, 0); // 2015-03-08T02:00
ZonedDateTime zod1 = ZonedDateTime.of(lod1, ZoneId.of("US/Eastern"));// 2015-03-08T03:00-04:00[US/Eastern] 
From the example above it is obvious when LocalDateTime object is applied to the ZoneDateTime with specific zone, the +1 hour is added automatically. The time has changed it can be seen from the print.

According to this functioning one would expect the same goes for the DST end
. But apparently it is not.
So at the 1st of November right at 2:00 the time should be changed for -1 hour.

Code: Select all

LocalDateTime ld1 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0);    // 2015-11-01T02:00
ZonedDateTime zd1 = ZonedDateTime.of(ld1, ZoneId.of("US/Eastern"));     // 2015-11-01T02:00-05:00[US/Eastern
The time of zd1 is not changed.

Thank you for your explanation.

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1750 :

Post by admin »

You seem to have misunderstood the DST logic. When the daylight saving is ON, only during that duration (i.e. during those months) the zone time is 1 hour plus from the local time. When the day light is not ON, the local time and zone time are same. So there is no reason to expect a difference when the dst has ended.

Now, the issue of plus and minus comes only when you transition from dst to non-dst or vice versa by adding or subtracting hours.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Wesley
Posts: 11
Joined: Sun Mar 18, 2018 9:08 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1750 :

Post by Wesley »

I got this question right but I still found it strange since on DST when the clocks go forward 2AM doesn't actually exist. The clock goes from 1:59.59 to 3:00.00. There is no 2AM. (assert mind == blown) So the question becomes how does Java interpret this phantom time? I haven't tested but according to the question it considers 2AM == 3AM.

If you don't understand the point I'm trying to make, think about this -> What if we set the time to 2:30AM and asked for the difference between 2:30 and 3:00 on that particular day? Without testing I have no idea if it will consider it 30 mins or also 0. My guess is it's programmed to take any time in the range 2:00 - 2:59 and bump it up to 3, so it'll also consider 2:30 AM to 3AM to be 0 minutes. Just a guess though.

nowkarol
Posts: 5
Joined: Sun Aug 05, 2018 5:41 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1750 :

Post by nowkarol »

We can state this question differently: which 1:00 will java create? We got two of theese. One with summer offset : -4 and one with normal (not DaylightSaving) : -5.

So we got 0:00 (offset -4), 1:00 (offset -4), 1:00 (offset -5).

Java by default will create date with offset prior to change (-4). With 2:00 there is no problem because this hour occures only with "new" offset (-5).

PS. This behavior can be changed by using withLaterOffsetAtOverlap on ZonedDateTime - called on zd2 in between method would result in -1.

I hope this thing will help, not confuse you more.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 29 guests