Merge pull request #8614 from alimate/BAEL-3754
Fixing Yet Another Date & Time Problem
This commit is contained in:
commit
402762888e
|
@ -4,6 +4,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
@ -18,12 +19,19 @@ public class ConvertToOffsetDateTimeUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenDate_whenHasOffset_thenConvertWithOffset() {
|
public void givenDate_whenHasOffset_thenConvertWithOffset() {
|
||||||
|
TimeZone prevTimezone = TimeZone.getDefault();
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
||||||
|
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
date.setHours(6);
|
date.setHours(6);
|
||||||
date.setMinutes(30);
|
date.setMinutes(30);
|
||||||
|
|
||||||
OffsetDateTime odt = ConvertToOffsetDateTime.convert(date, 3, 30);
|
OffsetDateTime odt = ConvertToOffsetDateTime.convert(date, 3, 30);
|
||||||
assertEquals(10, odt.getHour());
|
assertEquals(10, odt.getHour());
|
||||||
assertEquals(0, odt.getMinute());
|
assertEquals(0, odt.getMinute());
|
||||||
|
|
||||||
|
// Reset the timezone to its original value to prevent side effects
|
||||||
|
TimeZone.setDefault(prevTimezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue