WeekOfYear extends UDF { public Integer evaluate(String dateString) { if (dateString == null) { return null; } initDateFormat(); try { Date date = null; if (dateString.length() > UDFConstants.DATE_FORMAT.length()) { date = formatter1.parse(dateString); } else { date = formatter2.parse(dateString); } calendar.setTime(date); return calendar.get(Calendar.WEEK_OF_YEAR); } catch (ParseException e) { LOG.warn(EVALUATE_IGNORE_MESSAGE); return null; } } WeekOfYear(Map<String, String> config); Integer evaluate(String dateString); Integer evaluate(java.sql.Date d); Integer evaluate(Timestamp t);  }
@Test public void testEvaluate() { WeekOfYear udf = new WeekOfYear(null); assertTrue(udf.evaluate("2013-01-01 09:58:00.111") == TestUDFCommon.I_1); assertTrue(udf.evaluate("2013-01-01 09:58:00") == TestUDFCommon.I_1); assertTrue(udf.evaluate("2013-12-28") == TestUDFCommon.I_52); assertTrue(udf.evaluate("2013-12-52") == null); assertTrue(udf.evaluate("2013-01-01 09:58:70") == null); }
@Test public void testEvaluate2() { WeekOfYear udf = new WeekOfYear(null); ToDate todate = new ToDate(null); assertTrue(udf.evaluate(todate.evaluate("2013-1-1")) == TestUDFCommon.I_1); assertTrue(udf.evaluate(todate.evaluate("2013-01-01")) == TestUDFCommon.I_1); assertTrue(udf.evaluate(todate.evaluate("2013-12-28")) == TestUDFCommon.I_52); assertTrue(udf.evaluate(todate.evaluate("2013-12-52")) == null); }
@Test public void testEvaluate3() { WeekOfYear udf = new WeekOfYear(null); ToTimeStamp toTimeStamp = new ToTimeStamp(null); assertTrue(udf.evaluate(toTimeStamp.evaluate("2013-01-01 09:58:00.111")) == TestUDFCommon.I_1); assertTrue(udf.evaluate(toTimeStamp.evaluate("2013-01-01 09:58:00")) == TestUDFCommon.I_1); assertTrue(udf.evaluate(toTimeStamp.evaluate("2013-01-01 09:58:70")) == null); }