1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml.issues.issue141;
17
18 import java.util.Date;
19 import java.util.TimeZone;
20
21 import junit.framework.TestCase;
22
23 import org.yaml.snakeyaml.DumperOptions;
24 import org.yaml.snakeyaml.Yaml;
25
26 public class ConfigurableTimezoneTest extends TestCase {
27
28 public void testNoTimezone() {
29 Yaml yaml = new Yaml();
30 String output = yaml.dump(new Date());
31 assertTrue(output, output.endsWith("Z\n"));
32 }
33
34 public void testTimezone() {
35 DumperOptions options = new DumperOptions();
36 options.setTimeZone(TimeZone.getTimeZone("GMT+1:00"));
37 Yaml yaml = new Yaml(options);
38 Date date = new Date();
39 String output = yaml.dump(date);
40
41 assertTrue(output, output.trim().endsWith("+1:00"));
42 Date parsed = (Date) yaml.load(output);
43 assertEquals(date, parsed);
44 }
45 }