1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ch.qos.logback.core.util;
16
17 import java.text.ParseException;
18 import java.text.SimpleDateFormat;
19 import java.time.ZoneId;
20 import java.util.Date;
21 import java.util.TimeZone;
22
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25
26 import static org.junit.jupiter.api.Assertions.assertEquals;
27
28 public class CachingDateFotmatterTest {
29
30 private final static String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm";
31
32 SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
33 TimeZone perthTZ = TimeZone.getTimeZone("Australia/Perth");
34 TimeZone utcTZ = TimeZone.getTimeZone("UTC");
35
36 @BeforeEach
37 public void setUp() {
38 sdf.setTimeZone(utcTZ);
39 }
40
41 @Test
42 public void timeZoneIsTakenIntoAccount() throws ParseException {
43
44 ZoneId perthZone = ZoneId.of("Australia/Perth");
45 CachingDateFormatter cdf = new CachingDateFormatter(DATE_PATTERN, perthZone);
46
47 Date march26_2015_0949_UTC = sdf.parse("2015-03-26T09:49");
48 System.out.print(march26_2015_0949_UTC);
49
50 String result = cdf.format(march26_2015_0949_UTC.getTime());
51
52 assertEquals("2015-03-26T17:49", result);
53 }
54
55 }