PageRenderTime 25ms CodeModel.GetById 11ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/tags/release-0.2.0-rc0/hive/external/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFDateDiff.java

#
Java | 66 lines | 22 code | 14 blank | 30 comment | 0 complexity | 48b46bb9042062dd0442ea9e17647bbc MD5 | raw file
 1/**
 2 * Licensed to the Apache Software Foundation (ASF) under one
 3 * or more contributor license agreements.  See the NOTICE file
 4 * distributed with this work for additional information
 5 * regarding copyright ownership.  The ASF licenses this file
 6 * to you under the Apache License, Version 2.0 (the
 7 * "License"); you may not use this file except in compliance
 8 * with the License.  You may obtain a copy of the License at
 9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package org.apache.hadoop.hive.ql.udf;
20
21import org.apache.hadoop.io.IntWritable;
22import org.apache.hadoop.io.Text;
23
24import junit.framework.TestCase;
25
26import java.util.TimeZone;
27
28/**
29 * JUnit test for UDFDateDiff.
30 */
31public class TestUDFDateDiff extends TestCase {
32
33    /**
34     * Verify differences of dates crossing a daylight savings time change
35     * are correct.  The timezone tested is west coast US (PDT/PST) with a 
36     * 1 hour shift back in time at 02:00 AM on 2009-10-31 and a
37     * 1 hour shift forward in time at 02:00 AM on 2010-03-14.
38     */
39    public void testDaylightChange() throws Exception {
40        TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
41
42        // time moves ahead an hour at 02:00 on 2009-10-31
43        // which results in a 23 hour long day
44        Text date1 = new Text("2009-11-01");
45        Text date2 = new Text("2009-10-25");
46
47        IntWritable result = new UDFDateDiff().evaluate(date1, date2);
48        assertEquals(7, result.get());
49
50        result = new UDFDateDiff().evaluate(date2, date1);
51        assertEquals(-7, result.get());
52
53
54        // time moves back an hour at 02:00 on 2010-03-14
55        // which results in a 25 hour long day
56        date1 = new Text("2010-03-15");
57        date2 = new Text("2010-03-08");
58
59        result = new UDFDateDiff().evaluate(date1, date2);
60        assertEquals(7, result.get());
61
62        result = new UDFDateDiff().evaluate(date2, date1);
63        assertEquals(-7, result.get());
64
65    }
66}