Line 0
Link Here
|
|
|
1 |
/* ==================================================================== |
2 |
Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
contributor license agreements. See the NOTICE file distributed with |
4 |
this work for additional information regarding copyright ownership. |
5 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
(the "License"); you may not use this file except in compliance with |
7 |
the License. You may obtain a copy of the License at |
8 |
|
9 |
http://www.apache.org/licenses/LICENSE-2.0 |
10 |
|
11 |
Unless required by applicable law or agreed to in writing, software |
12 |
distributed under the License is distributed on an "AS IS" BASIS, |
13 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
See the License for the specific language governing permissions and |
15 |
limitations under the License. |
16 |
==================================================================== */ |
17 |
|
18 |
package org.apache.poi.ss.usermodel; |
19 |
|
20 |
import static org.junit.Assert.assertEquals; |
21 |
|
22 |
import java.util.Calendar; |
23 |
import java.util.Date; |
24 |
import java.util.TimeZone; |
25 |
|
26 |
import org.junit.Test; |
27 |
|
28 |
public class TestDateUtil { |
29 |
|
30 |
@Test |
31 |
public void getJavaDate_InvalidValue() { |
32 |
double dateValue = -1; |
33 |
TimeZone tz = TimeZone.getDefault(); |
34 |
boolean use1904windowing = false; |
35 |
boolean roundSeconds = false; |
36 |
|
37 |
assertEquals(null, DateUtil.getJavaDate(dateValue)); |
38 |
assertEquals(null, DateUtil.getJavaDate(dateValue, tz)); |
39 |
assertEquals(null, DateUtil.getJavaDate(dateValue, use1904windowing)); |
40 |
assertEquals(null, DateUtil.getJavaDate(dateValue, use1904windowing, tz)); |
41 |
assertEquals(null, DateUtil.getJavaDate(dateValue, use1904windowing, tz, roundSeconds)); |
42 |
} |
43 |
|
44 |
@Test |
45 |
public void getJavaDate_ValidValue() { |
46 |
double dateValue = 0; |
47 |
TimeZone tz = TimeZone.getDefault(); |
48 |
boolean use1904windowing = false; |
49 |
boolean roundSeconds = false; |
50 |
|
51 |
Calendar calendar = Calendar.getInstance(tz); |
52 |
calendar.set(1900, 0, 0, 0, 0, 0); |
53 |
calendar.set(Calendar.MILLISECOND, 0); |
54 |
Date date = calendar.getTime(); |
55 |
|
56 |
assertEquals(date, DateUtil.getJavaDate(dateValue)); |
57 |
assertEquals(date, DateUtil.getJavaDate(dateValue, tz)); |
58 |
assertEquals(date, DateUtil.getJavaDate(dateValue, use1904windowing)); |
59 |
assertEquals(date, DateUtil.getJavaDate(dateValue, use1904windowing, tz)); |
60 |
assertEquals(date, DateUtil.getJavaDate(dateValue, use1904windowing, tz, roundSeconds)); |
61 |
} |
62 |
|
63 |
@Test |
64 |
public void getJavaCalendar_InvalidValue() { |
65 |
double dateValue = -1; |
66 |
TimeZone tz = TimeZone.getDefault(); |
67 |
boolean use1904windowing = false; |
68 |
boolean roundSeconds = false; |
69 |
|
70 |
assertEquals(null, DateUtil.getJavaCalendar(dateValue)); |
71 |
assertEquals(null, DateUtil.getJavaCalendar(dateValue, use1904windowing)); |
72 |
assertEquals(null, DateUtil.getJavaCalendar(dateValue, use1904windowing, tz)); |
73 |
assertEquals(null, DateUtil.getJavaCalendar(dateValue, use1904windowing, tz, roundSeconds)); |
74 |
} |
75 |
|
76 |
@Test |
77 |
public void getJavaCalendar_ValidValue() { |
78 |
double dateValue = 0; |
79 |
TimeZone tz = TimeZone.getDefault(); |
80 |
boolean use1904windowing = false; |
81 |
boolean roundSeconds = false; |
82 |
|
83 |
Calendar calendar = Calendar.getInstance(tz); |
84 |
calendar.set(1900, 0, 0, 0, 0, 0); |
85 |
calendar.set(Calendar.MILLISECOND, 0); |
86 |
|
87 |
assertEquals(calendar, DateUtil.getJavaCalendar(dateValue)); |
88 |
assertEquals(calendar, DateUtil.getJavaCalendar(dateValue, use1904windowing)); |
89 |
assertEquals(calendar, DateUtil.getJavaCalendar(dateValue, use1904windowing, tz)); |
90 |
assertEquals(calendar, DateUtil.getJavaCalendar(dateValue, use1904windowing, tz, roundSeconds)); |
91 |
} |
92 |
} |