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