formatting

This commit is contained in:
Loredana Crusoveanu 2018-03-24 10:22:40 +02:00
parent 068a21f32a
commit d12be45fe1
2 changed files with 19 additions and 8 deletions

View File

@ -25,7 +25,7 @@ public class DaylightSavingTimeExamplesTest {
cal.setTime(dateBeforeDST); cal.setTime(dateBeforeDST);
System.out.println("Before DST (00:55 UTC - 01:55 GMT+1) = " + dateBeforeDST); System.out.println("Before DST (00:55 UTC - 01:55 GMT+1) = " + dateBeforeDST);
System.out.println("With this Calendar " + (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000) + " minutes must be added to UTC (GMT TimeZone) to get a correct date for this TimeZone\n"); System.out.println("With this Calendar " + (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000) + " minutes must be added to UTC (GMT TimeZone) to get a correct date for this TimeZone\n");
assertThat(cal.get(Calendar.ZONE_OFFSET)).isEqualTo(3600000); assertThat(cal.get(Calendar.ZONE_OFFSET)).isEqualTo(3600000);
assertThat(cal.get(Calendar.DST_OFFSET)).isEqualTo(0); assertThat(cal.get(Calendar.DST_OFFSET)).isEqualTo(0);
@ -33,7 +33,7 @@ public class DaylightSavingTimeExamplesTest {
cal.add(Calendar.MINUTE, 10); cal.add(Calendar.MINUTE, 10);
Date dateAfterDST = cal.getTime(); Date dateAfterDST = cal.getTime();
System.out.println(" After DST (01:05 UTC - 03:05 GMT+2) = " + dateAfterDST); System.out.println(" After DST (01:05 UTC - 03:05 GMT+2) = " + dateAfterDST);
System.out.println("With this Calendar " + (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000) + " minutes must be added to UTC (GMT TimeZone) to get a correct date for this TimeZone\n"); System.out.println("With this Calendar " + (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000) + " minutes must be added to UTC (GMT TimeZone) to get a correct date for this TimeZone\n");
assertThat(cal.get(Calendar.DST_OFFSET)).isEqualTo(3600000); assertThat(cal.get(Calendar.DST_OFFSET)).isEqualTo(3600000);
@ -45,8 +45,15 @@ public class DaylightSavingTimeExamplesTest {
} }
private void prettyPrint(TimeZone tz) { private void prettyPrint(TimeZone tz) {
System.out.println(
String.format(" Zone ID = %s (%s)\n" + " RawOffset = %s minutes\n" + " DST = %s minutes\n" + " -----------------------------------------", tz.getID(), tz.getDisplayName(), tz.getRawOffset() / 60000, tz.getDSTSavings() / 60000)); //@formatter:off
System.out.println(String.format(
" Zone ID = %s (%s)\n"
+ " RawOffset = %s minutes\n"
+ " DST = %s minutes\n"
+ " -----------------------------------------",
tz.getID(), tz.getDisplayName(), tz.getRawOffset()/60000, tz.getDSTSavings()/60000));
//@formatter:on
} }
@Test @Test

View File

@ -35,10 +35,14 @@ public class DaylightSavingTimeJavaTimeExamplesTest {
} }
private void prettyPrint(ZonedDateTime zdt) { private void prettyPrint(ZonedDateTime zdt) {
System.out.println(String.format(" ZonedDateTime = %s\n" + " Zone ID = %s (%s)\n" + " RawOffset = %s minutes\n" + " -----------------------------------------", zdt, zdt.getZone(), zdt.getZone() //@formatter:off
.getId(), System.out.println(String.format(
zdt.getOffset() " ZonedDateTime = %s\n"
.getTotalSeconds() / 60)); + " Zone ID = %s (%s)\n"
+ " RawOffset = %s minutes\n"
+ " -----------------------------------------",
zdt, zdt.getZone(), zdt.getZone().getId(), zdt.getOffset().getTotalSeconds()/60));
//@formatter:on
} }
@Test @Test