@Override public Object create(Object request, SpecimenContext context) { if (!(request instanceof SpecimenType)) { return new NoSpecimen(); } SpecimenType type = (SpecimenType) request; if (!BaseDateTime.class.isAssignableFrom(type.getRawType())) { return new NoSpecimen(); } try { Date date = (Date) context.resolve(Date.class); long instant = date.getTime(); DateTimeZone timeZone = (DateTimeZone)context.resolve(DateTimeZone.class); return type.getRawType().getDeclaredConstructor(long.class, DateTimeZone.class).newInstance(instant, timeZone); } catch (Exception e) { e.printStackTrace(); return new NoSpecimen(); } }
/** Pass components of {@code dt} to {@link #encodeDateTime(long, long, long, long, long, long)}. */ public static long encodeDateTime(BaseDateTime dt) { return encodeDateTime(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute()); }
/** Convert {@code dateTime} to milliseconds and {@link #encodeTimestamp(long, TExecutionContext)}. */ public static int encodeTimestamp(BaseDateTime dateTime, TExecutionContext context) { return encodeTimestamp(dateTime.getMillis(), context); }
public static boolean isValidTimestamp(BaseDateTime dt) { long millis = dt.getMillis(); return (millis >= TIMESTAMP_MIN) && (millis <= TIMESTAMP_MAX); }
public BaseDateTime getStartWallTime(String timezone) { String[] tokens = file.getName().split("_"); return StarTreeConstants.DATE_TIME_FORMATTER.withZone(DateTimeZone.forID(timezone)).parseDateTime(tokens[2]); }
@Override public BaseDateTime getDateTime() { return new DateTime(_gregorianYear, _gregorianMonth, _gregorianDay, 0, 0); }
/** * Creates a BadiDate from Joda DateTime. * * @param Joda * DateTime * @return The Badi date * @throws IllegalArgumentException * Year is less than 1844 or greater than UPPER_YEAR_LIMIT */ public static BadiDate createFromDateTime(final BaseDateTime gregorianDate) throws IllegalArgumentException { final int year = gregorianDate.getYear(); checkGregorianYearForValidity(year); final int doy = gregorianDate.getDayOfYear(); return createFromGregorianDoyAndYear(year, doy); }
/** * Creates a BadiDate from Joda DateTime and considers if the sun has set. * * @param Joda * DateTime * @param sunset * Has the sun set? * @return The Badi date * @throws IllegalArgumentException * Year is less than 1844 or greater than UPPER_YEAR_LIMIT */ public static BadiDate createFromDateTimeWithSunset(final BaseDateTime gregorianDate, final boolean sunset) throws IllegalArgumentException { final int year = gregorianDate.getYear(); checkGregorianYearForValidity(year); final int doy = gregorianDate.getDayOfYear() + (sunset==true ? 1 : 0); return createFromGregorianDoyAndYear(year, doy); }
/** * Returns the Joda time for the Gregorian date. */ BaseDateTime getDateTime();