Last active
July 17, 2018 04:29
-
-
Save hakanai/f66970dcc6aa418e823191aea3322795 to your computer and use it in GitHub Desktop.
Welcome to in Ireland, the only country where the clock is turned _back_ for daylight saving time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Joda Time --- | |
Winter: | |
Monday, 1 January 2018 12:00:00 AM GMT | |
Is standard offset? true | |
Summer: | |
Sunday, 1 July 2018 1:00:00 AM IST | |
Is standard offset? false | |
--- ICU --- | |
Winter: | |
Monday, 1 January 2018 at 12:00:00 am Greenwich Mean Time | |
Is standard offset? false | |
Summer: | |
Sunday, 1 July 2018 at 1:00:00 am Irish Standard Time | |
Is standard offset? true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Locale; | |
import com.ibm.icu.text.DateFormat; | |
import com.ibm.icu.util.Calendar; | |
import com.ibm.icu.util.TimeZone; | |
import org.joda.time.DateTime; | |
import org.joda.time.DateTimeZone; | |
import org.joda.time.format.DateTimeFormat; | |
import org.joda.time.format.DateTimeFormatter; | |
import org.junit.Test; | |
public class TestIreland | |
{ | |
@Test | |
public void testIrelandJoda() | |
{ | |
System.out.println("--- Joda Time ---"); | |
DateTimeZone zone = DateTimeZone.forID("Europe/Dublin"); | |
DateTimeFormatter dateTimeFormatter = DateTimeFormat.fullDateTime().withZone(zone); | |
System.out.println("Winter:"); | |
DateTime dateTime1 = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeZone.UTC).withZone(zone); | |
System.out.println(dateTimeFormatter.print(dateTime1)); | |
System.out.println("Is standard offset? " + zone.isStandardOffset(dateTime1.getMillis())); | |
System.out.println("Summer:"); | |
DateTime dateTime2 = new DateTime(2018, 7, 1, 0, 0, 0, DateTimeZone.UTC).withZone(zone); | |
System.out.println(dateTimeFormatter.print(dateTime2)); | |
System.out.println("Is standard offset? " + zone.isStandardOffset(dateTime2.getMillis())); | |
} | |
@Test | |
public void testIrelandIcu() | |
{ | |
System.out.println("--- ICU ---"); | |
TimeZone zone = TimeZone.getTimeZone("Europe/Dublin"); | |
Locale locale = new Locale("en", "IE"); | |
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); | |
dateFormat.setTimeZone(zone); | |
Calendar calendar = Calendar.getInstance(zone, locale); | |
System.out.println("Winter:"); | |
calendar.setTimeInMillis(new DateTime(2018, 1, 1, 0, 0, 0, DateTimeZone.UTC).getMillis()); | |
System.out.println(dateFormat.format(calendar.getTime())); | |
System.out.println("Is standard offset? " + zone.inDaylightTime(calendar.getTime())); | |
System.out.println("Summer:"); | |
calendar.setTimeInMillis(new DateTime(2018, 7, 1, 0, 0, 0, DateTimeZone.UTC).getMillis()); | |
System.out.println(dateFormat.format(calendar.getTime())); | |
System.out.println("Is standard offset? " + zone.inDaylightTime(calendar.getTime())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment