org.joda.time.base.BaseDateTime Java Examples

The following examples show how to use org.joda.time.base.BaseDateTime. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseDateTimeRelay.java    From jfixture with MIT License 6 votes vote down vote up
@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();
    }
}
 
Example #2
Source File: MDateAndTime.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
/** 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());
}
 
Example #3
Source File: MDateAndTime.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
/** Convert {@code dateTime} to milliseconds and {@link #encodeTimestamp(long, TExecutionContext)}. */
public static int encodeTimestamp(BaseDateTime dateTime, TExecutionContext context) {
    return encodeTimestamp(dateTime.getMillis(), context);
}
 
Example #4
Source File: MDateAndTime.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean isValidTimestamp(BaseDateTime dt) {
    long millis = dt.getMillis();
    return (millis >= TIMESTAMP_MIN) && (millis <= TIMESTAMP_MAX);
}