About Question enthuware.ocpjp.v8.2.1749 :
Moderator: admin
-
- Posts: 4
- Joined: Tue Feb 17, 2015 9:54 am
- Contact:
About Question enthuware.ocpjp.v8.2.1749 :
I didn't get it...
"Given that daylight Savings Time ends on Nov 1 at 2 AM in US/Eastern time zone. (As a result, 2 AM becomes 1 AM.), what will the following code print?"
If you have Nov/01 01:00AM it means you have 01:00.
If you have Nov/01 02:00AM it means you have 01:00.
Since the daylight savings ends exactly in nov 1 02:00AM, then the Nov/01 01:00AM should be still 01:00AM and Nov/01 02:00AM as well.
I compiled and ran the code and it printed -2, but I still didn't get it.
How 1 - 1 == -2?
"Given that daylight Savings Time ends on Nov 1 at 2 AM in US/Eastern time zone. (As a result, 2 AM becomes 1 AM.), what will the following code print?"
If you have Nov/01 01:00AM it means you have 01:00.
If you have Nov/01 02:00AM it means you have 01:00.
Since the daylight savings ends exactly in nov 1 02:00AM, then the Nov/01 01:00AM should be still 01:00AM and Nov/01 02:00AM as well.
I compiled and ran the code and it printed -2, but I still didn't get it.
How 1 - 1 == -2?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
1-1 is not -2. On Nov 1, at 2AM, the display changes back to 1AM. So that means, even after adding the first one hour to 1 AM, you still have the time showing as 1 AM. So to go to 2AM, you need to add one more hour. Therefore, the total number of hours that you added is 2. Therefore, 1AM - 2AM is -2.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 17
- Joined: Thu Oct 01, 2015 4:06 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
In fact we have 2 AM twice. What about the case when we want to get 2 AM witch comes after clock changes back?
When we call LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0); how the System knows witch of 2 time points we means ?
When we call LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0); how the System knows witch of 2 time points we means ?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
System doesn't keep time in timezones or even in hours minutes seconds. It keeps the time in the form of total seconds elapsed after the epoch (e.g. start of the Unix epoch is at 1 January 1970 00:00:00 UT). So it doesn't matter to the system whether you call a particular time as 1st Nov 1AM or 1st Nov 2AM. As far as the system is concerned "the total seconds elapsed since the epoch" for "2AM before the shift" and "the total seconds elapsed since the epoch" for "2AM after the shift" are two different numbers.
If you like our products and services, please help us by posting your review here.
-
- Posts: 3
- Joined: Sat May 28, 2016 2:10 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
I understand lucasheitich's concerns about this question and I do get the explanation to this question as well.
Until... I stopped at a very similar question just with the DST Start Date.
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
lucasheitich's initial post?
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?
Thank you for your help.
Until... I stopped at a very similar question just with the DST Start Date.
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
lucasheitich's initial post?
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]
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
Answered here: viewtopic.php?f=2&t=3875
If you like our products and services, please help us by posting your review here.
-
- Posts: 106
- Joined: Mon Mar 28, 2016 11:36 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
What do you mean when you said "it returns negative value if the end is before the start"?The answer can therefore be short listed to 2 or -2. Now, as per the JavaDoc description of the between method, it returns negative value if the end is before the start. In the given code, our end date is 1AM, while the start date is 2AM. This means, the answer is -2.
Is that because end aka zd2 (01:00 AM) is less than start aka zd1 (02:00 AM)? Those of us in N. America also know that end is still in summer time zone and start is in winter time zone.
How do you compare 2 things in different time zones and say that one comes before the other?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
1. Yes, 1AM occurs before 2AM.
2. It is talking about the same time zone. Where do you see different time zones?
2. It is talking about the same time zone. Where do you see different time zones?
If you like our products and services, please help us by posting your review here.
-
- Posts: 106
- Joined: Mon Mar 28, 2016 11:36 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
I ran your code with some print statements and I've got the following:admin wrote:1. Yes, 1AM occurs before 2AM.
2. It is talking about the same time zone. Where do you see different time zones?
zd1 = 1 2015-11-01T02:00-05:00[US/Eastern] <==== Entering winter time in N. America. Offset of -5 here.
zd2 = 2 2015-11-01T01:00-04:00[US/Eastern] <==== Still in summer time in N. America. Offset of -4 here.
In that case, are you not comparing 2 different times in 2 different time zones?
Therefore, how do you draw the conclusion that one comes before another?
Would you reason that summer (i.e. end aka zd2) comes before winter (i.e. start aka zd1), given the simulation results?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
Time zone is same i.e. US/Eastern. Daylight start or end doesn't change the time zone. Only the zone offset wrt to GMT depends on whether dst is on or off.
If you like our products and services, please help us by posting your review here.
-
- Posts: 106
- Joined: Mon Mar 28, 2016 11:36 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
I see. Thank you.admin wrote:Time zone is same i.e. US/Eastern. Daylight start or end doesn't change the time zone. Only the zone offset wrt to GMT depends on whether dst is on or off.
-
- Posts: 4
- Joined: Fri Sep 30, 2016 4:44 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
Program does not compiles . As per i know for comparision zoneddatetime must be converted into instant to remove timezone...
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
Please try the exact code that is given it the question. It compiles and runs fine.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 7
- Joined: Wed Jun 25, 2014 12:44 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
I think it is always good to pick the time that is before the DST when one is before DST and another is after DST. In this case it is LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 0) and LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0) respectively.
Then, add up 1 hour at a time to the time (which is before DST ) in order to reach the other time after DST.
so add 1 more to the above result:
we add 2 hours in total to get to the other time.
See here: http://tpcg.io/LUCsMp
Then, add up 1 hour at a time to the time (which is before DST ) in order to reach the other time after DST.
Code: Select all
LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 0) + 1 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0) which becomes LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 0)
Code: Select all
(LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 0) + 1) + 1 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0)
See here: http://tpcg.io/LUCsMp
-
- Posts: 11
- Joined: Sun Mar 18, 2018 9:08 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
To be honest, I don't care much for this question. It assumes knowledge how Java will behave when you set it 1AM on the day the clocks go back. On that day we have two 1AMs. How does Java know which one we are referring to when we set the time?
If it were the 2nd 1AM then the time difference would only be 1 hour. It would have been less ambiguous if it was 12:59am to 2PM. Then we could say without a doubt that it'll take 2 hours and 1 minute. It seems like it's testing us on a very specific and rare corner case. Although.. if the test-makers at Oracle write questions like this it'll be good practice for us. But even in that case I would argue that they designed the question poorly.
Again, just my two cents. It's not like it's important or anything.
If it were the 2nd 1AM then the time difference would only be 1 hour. It would have been less ambiguous if it was 12:59am to 2PM. Then we could say without a doubt that it'll take 2 hours and 1 minute. It seems like it's testing us on a very specific and rare corner case. Although.. if the test-makers at Oracle write questions like this it'll be good practice for us. But even in that case I would argue that they designed the question poorly.
Again, just my two cents. It's not like it's important or anything.
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
I have been playing around with this and what seems to be the case is that when the clocks go back, java sees any time before 2am as "pre-DST change" and any time from 2am onwards as "post-DST change":
Please correct me if I'm wrong.
Code: Select all
LocalDateTime ld1 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 59);
ZonedDateTime zd1 = ZonedDateTime.of(ld1, ZoneId.of("US/Eastern"));
LocalDateTime ld2 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0);
ZonedDateTime zd2 = ZonedDateTime.of(ld2, ZoneId.of("US/Eastern"));
long m = ChronoUnit.MINUTES.between(zd1, zd2); System.out.println(m); //61
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
That sounds correct.
If you like our products and services, please help us by posting your review here.
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
-
- Posts: 33
- Joined: Sat Feb 15, 2020 12:44 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
To grasp this concept fully you have to understand, that if it already is 2 am in LocalDateTime, then the time change already happened. The clock is NOT turned back to 1 am!
2 am stays 2 am and now the question is how long does it take to go from 1 am to 2 am considering the time change. It takes, of course, 2 hours.
2 am stays 2 am and now the question is how long does it take to go from 1 am to 2 am considering the time change. It takes, of course, 2 hours.
-
- Posts: 1
- Joined: Thu May 30, 2019 8:16 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
in Poland we change time Zone from CET - Central European Time (GMT+1) to CEST - Central European Sumer Time (GMT+2). this is very confusing that they using the same name for difrent Zone. If they change time zone, they should use difrent time zone name, but stil have the same offset from GMT.
how did they know on witch 1:01 AM they have? before or after change to summer time?
how did they know on witch 1:01 AM they have? before or after change to summer time?
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 103 guests