MDateAndTime { public static long[] parseDateTime(long val) { if((val != 0) && (val <= 100)) { throw new InvalidDateFormatException("date", Long.toString(val)); } if(val < DATETIME_MONTH_SCALE) { val *= DATETIME_DATE_SCALE; } long[] dt = decodeDateTime(val); if(val != 0) { dt[YEAR_INDEX] = adjustTwoDigitYear(dt[YEAR_INDEX]); } if(!isValidDateTime_Zeros(dt)) { throw new InvalidDateFormatException("date", Long.toString(val)); } if(!isValidHrMinSec(dt, true, true)) { throw new InvalidDateFormatException("datetime", Long.toString(val)); } return dt; }  static String getMonthName(int numericRep, String locale, TExecutionContext context); static long[] fromJodaDateTime(AbstractDateTime date); static MutableDateTime toJodaDateTime(long[] dt, String tz); static MutableDateTime toJodaDateTime(long[] dt, DateTimeZone dtz); static String dateToString(int encodedDate); static int parseAndEncodeDate(String input); static int encodeDate(long millis, String tz); static int encodeDate(long[] dt); static int encodeDate(long y, long m, long d); static long[] decodeDate(long encodedDate); static long[] parseDate(long val); static long[] parseDateTime(long val); static String dateTimeToString(long encodedDateTime); static String dateTimeToString(long[] dt); static StringType parseDateOrTime(String st, long[] dt); static long parseAndEncodeDateTime(String input); static long encodeDateTime(long millis, String tz); static long encodeDateTime(BaseDateTime dt); static long encodeDateTime(long[] dt); static long encodeDateTime(long year, long month, long day, long hour, long min, long sec); static long[] decodeDateTime(long encodedDateTime); static String timeToString(int encodedTime); static String timeToString(long[] dt); static String timeToString(long h, long m, long s); static void timeToDatetime(long[] dt); static int parseTime(String string, TExecutionContext context); static long[] decodeTime(long encodedTime); static int encodeTime(long millis, String tz); static int encodeTime(long[] dt, TExecutionContext context); static int encodeTime(long h, long m, long s, TExecutionContext context); static int parseAndEncodeTimestamp(String input, String tz, TExecutionContext context); static long[] decodeTimestamp(long encodedTimestamp, String tz); static int encodeTimestamp(long[] dt, String tz, TExecutionContext context); static int encodeTimestamp(BaseDateTime dateTime, TExecutionContext context); static int encodeTimestamp(long millis, TExecutionContext context); static boolean isValidTimestamp(BaseDateTime dt); static int getTimestamp(long[] dt, String tz); static String timestampToString(long encodedTimestamp, String tz); static DateTimeZone parseTimeZone(String tz); static boolean isValidDateTime_Zeros(long[] dt); static boolean isValidDateTime(long[] dt, ZeroFlag... flags); static boolean isHrMinSecNegative(long[] dt); static boolean isHrMinSecNegative(long h, long m, long s); static boolean isValidHrMinSec(long[] dt, boolean checkHour, boolean isFromDateTime); static boolean isValidHrMinSec(long h, long m, long s, boolean checkHour, boolean isFromDateTime); static boolean isZeroDayMonth(long[] dt); static boolean isValidDate_Zeros(long[] dt); static boolean isValidDate_NoZeros(long[] dt); static boolean isValidDate(long[] dt, ZeroFlag... flags); static boolean isValidDate(long y, long m, long d, ZeroFlag... flags); static long getLastDay(long[] dt); static long getLastDay(long year, long month); static boolean isValidType(StringType type); static final NoAttrTClass DATE; static final NoAttrTClass DATETIME; static final NoAttrTClass TIME; static final NoAttrTClass YEAR; static final NoAttrTClass TIMESTAMP; static final Map<String, String[]> MONTHS; static final int YEAR_INDEX; static final int MONTH_INDEX; static final int DAY_INDEX; static final int HOUR_INDEX; static final int MIN_INDEX; static final int SEC_INDEX; static final int MAX_INDEX; static final long TIMESTAMP_MIN; static final long TIMESTAMP_MAX; static final long TS_ERROR_VALUE; static final int TIME_MAX; static final int TIME_MIN; }
@Test public void testParseDateTime_long() { arrayEquals(dt(0), parseDateTime(0)); try { parseDateTime(100); fail("expected invalid"); } catch(InvalidDateFormatException e) { } arrayEquals(dt(2000, 5, 1), parseDateTime(501)); arrayEquals(dt(2005, 5, 1), parseDateTime(50501)); arrayEquals(dt(1995, 5, 1), parseDateTime(950501)); arrayEquals(dt(1995, 5, 1), parseDateTime(19950501)); arrayEquals(dt(1995, 12, 31), parseDateTime(19951231)); arrayEquals(dt(2000, 1, 1), parseDateTime(20000101)); arrayEquals(dt(9999, 12, 31), parseDateTime(99991231)); arrayEquals(dt(2000, 0, 0), parseDateTime(20000000)); arrayEquals(dt(2000, 0, 1), parseDateTime(20000001)); arrayEquals(dt(2000, 1, 0), parseDateTime(20000100)); arrayEquals(dt(2000, 3, 0), parseDateTime(20000300)); arrayEquals(dt(1999, 3, 0), parseDateTime(19990300)); try { parseDateTime(20000231); fail("expected invalid"); } catch(InvalidDateFormatException e) { } arrayEquals(dt(110, 11, 12, 0, 0, 0), parseDateTime(1101112)); arrayEquals(dt(1995, 5, 1, 10, 11, 12), parseDateTime(950501101112L)); arrayEquals(dt(1995, 5, 1, 10, 11, 12), parseDateTime(19950501101112L)); }