summaryrefslogtreecommitdiffstats
blob: e6fc78789787dc1982699f41ec4470391563b927 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*  Copyright (c) 2016, Isode Limited, London, England.
 *  All rights reserved.
 *
 *  Acquisition and use of this software and related materials for any
 *  purpose requires a written license agreement from Isode Limited,
 *  or a written license from an organisation licensed by Isode Limited
 *  to grant such a license.
 *
 */
package com.isode.stroke.base;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

import org.junit.Before;
import org.junit.Test;

/**
 * @author ac
 * @since 16.5
 *
 */
public class DateTimeTest {

    private final SimpleDateFormat isoFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

    @Before
    public void setUp() {
        isoFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    }
    
    @Test
    public void testStringToDateTime_UTC() {
        Date time = DateTime.stringToDate("1969-07-21T02:56:15Z");
        assertNotNull(time);
        assertEquals("1969-07-21T02:56:15", isoFormatter.format(time));
    }
    
    @Test
    public void testStringToDateTime_WithTimezone() {
        Date time = DateTime.stringToDate("1969-07-20T21:56:15-05:00");
        assertNotNull(time);
        assertEquals("1969-07-21T02:56:15", isoFormatter.format(time));
    }
    
    @Test
    public void testDateTimeToString() {
        Date time = DateTime.stringToDate("1969-07-20T21:56:15-05:00");
        assertEquals("1969-07-21T02:56:15Z", DateTime.dateToString(time));
    }
    
}