PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.0.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
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  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. package org.apache.hadoop.hive.ql.udf;
  19. import org.apache.hadoop.io.IntWritable;
  20. import org.apache.hadoop.io.Text;
  21. import junit.framework.TestCase;
  22. import java.util.TimeZone;
  23. /**
  24. * JUnit test for UDFDateDiff.
  25. */
  26. public class TestUDFDateDiff extends TestCase {
  27. /**
  28. * Verify differences of dates crossing a daylight savings time change
  29. * are correct. The timezone tested is west coast US (PDT/PST) with a
  30. * 1 hour shift back in time at 02:00 AM on 2009-10-31 and a
  31. * 1 hour shift forward in time at 02:00 AM on 2010-03-14.
  32. */
  33. public void testDaylightChange() throws Exception {
  34. TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
  35. // time moves ahead an hour at 02:00 on 2009-10-31
  36. // which results in a 23 hour long day
  37. Text date1 = new Text("2009-11-01");
  38. Text date2 = new Text("2009-10-25");
  39. IntWritable result = new UDFDateDiff().evaluate(date1, date2);
  40. assertEquals(7, result.get());
  41. result = new UDFDateDiff().evaluate(date2, date1);
  42. assertEquals(-7, result.get());
  43. // time moves back an hour at 02:00 on 2010-03-14
  44. // which results in a 25 hour long day
  45. date1 = new Text("2010-03-15");
  46. date2 = new Text("2010-03-08");
  47. result = new UDFDateDiff().evaluate(date1, date2);
  48. assertEquals(7, result.get());
  49. result = new UDFDateDiff().evaluate(date2, date1);
  50. assertEquals(-7, result.get());
  51. }
  52. }