Example usage for org.joda.time DateTimeZone getDefault

List of usage examples for org.joda.time DateTimeZone getDefault

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone getDefault.

Prototype

public static DateTimeZone getDefault() 

Source Link

Document

Gets the default time zone.

Usage

From source file:io.prestosql.plugin.hive.util.SerDeUtils.java

License:Apache License

private static long formatDateAsLong(Object object, DateObjectInspector inspector) {
    if (object instanceof LazyDate) {
        return ((LazyDate) object).getWritableObject().getDays();
    }//www . j  a va 2 s .co m
    if (object instanceof DateWritable) {
        return ((DateWritable) object).getDays();
    }

    // Hive will return java.sql.Date at midnight in JVM time zone
    long millisLocal = inspector.getPrimitiveJavaObject(object).getTime();
    // Convert it to midnight in UTC
    long millisUtc = DateTimeZone.getDefault().getMillisKeepLocal(DateTimeZone.UTC, millisLocal);
    // Convert midnight UTC to days
    return TimeUnit.MILLISECONDS.toDays(millisUtc);
}

From source file:io.prestosql.plugin.jdbc.StandardColumnMappings.java

License:Apache License

public static LongWriteFunction dateWriteFunction() {
    return (statement, index, value) -> {
        // convert to midnight in default time zone
        long millis = DAYS.toMillis(value);
        statement.setDate(index, new Date(UTC.getMillisKeepLocal(DateTimeZone.getDefault(), millis)));
    };//from w w w .ja  v a 2s . c  o m
}

From source file:io.prestosql.tests.H2QueryRunner.java

License:Apache License

private static void insertRows(ConnectorTableMetadata tableMetadata, Handle handle, RecordSet data) {
    List<ColumnMetadata> columns = tableMetadata.getColumns().stream()
            .filter(columnMetadata -> !columnMetadata.isHidden()).collect(toImmutableList());

    String vars = Joiner.on(',').join(nCopies(columns.size(), "?"));
    String sql = format("INSERT INTO %s VALUES (%s)", tableMetadata.getTable().getTableName(), vars);

    RecordCursor cursor = data.cursor();
    while (true) {
        // insert 1000 rows at a time
        PreparedBatch batch = handle.prepareBatch(sql);
        for (int row = 0; row < 1000; row++) {
            if (!cursor.advanceNextPosition()) {
                if (batch.size() > 0) {
                    batch.execute();/*w w w. java2 s . c o m*/
                }
                return;
            }
            for (int column = 0; column < columns.size(); column++) {
                Type type = columns.get(column).getType();
                if (BOOLEAN.equals(type)) {
                    batch.bind(column, cursor.getBoolean(column));
                } else if (BIGINT.equals(type)) {
                    batch.bind(column, cursor.getLong(column));
                } else if (INTEGER.equals(type)) {
                    batch.bind(column, (int) cursor.getLong(column));
                } else if (DOUBLE.equals(type)) {
                    batch.bind(column, cursor.getDouble(column));
                } else if (type instanceof VarcharType) {
                    batch.bind(column, cursor.getSlice(column).toStringUtf8());
                } else if (DATE.equals(type)) {
                    long millisUtc = TimeUnit.DAYS.toMillis(cursor.getLong(column));
                    // H2 expects dates in to be millis at midnight in the JVM timezone
                    long localMillis = DateTimeZone.UTC.getMillisKeepLocal(DateTimeZone.getDefault(),
                            millisUtc);
                    batch.bind(column, new Date(localMillis));
                } else {
                    throw new IllegalArgumentException("Unsupported type " + type);
                }
            }
            batch.add();
        }
        batch.execute();
    }
}

From source file:io.smartspaces.time.provider.LocalTimeProvider.java

License:Apache License

@Override
public DateTimeZone getPlatformDateTimeZone() {
    return DateTimeZone.getDefault();
}

From source file:jp.furplag.util.Localizer.java

License:Apache License

/**
 * create {@link DateTimeZone}.//from   w  w w . java  2  s  . c o  m
 *
 * <pre>
 * newDateTimeZone(null) = DateTimeZone.getDefault()
 * newDateTimeZone("") = DateTimeZone.UTC
 * newDateTimeZone(9) = DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT+0900"))
 * newDateTimeZone(-9) = DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT-0900"))
 * newDateTimeZone("9") = DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT+0900"))
 * newDateTimeZone("-9") = DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT-0900"))
 * newDateTimeZone("Etc/GMT-9") = DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT-0900"))
 * newDateTimeZone("Etc/GMT-9") = DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT+0900"))
 * </pre>
 * <p>
 * fallback to similar timezone if deprecated time zone specified.
 * </p>
 *
 * <pre>
 * newDateTimeZone("SystemV/EST5") = DateTimeZone.forID("Etc/GMT+5")
 * newDateTimeZone("Mideast/Riyadh87") = DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT+0307"))
 * </pre>
 * <p>
 * minutes, millis also specifiable.
 * </p>
 *
 * <pre>
 * newDateTimeZone("SystemV/EST5") = DateTimeZone.forID("Etc/GMT+5")
 * newDateTimeZone("Mideast/Riyadh87") = DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT+0307"))
 * </pre>
 *
 * @param zone timezone ( {@link String}, {@link TimeZone}, and {@link DateTimeZone} specifiable ). Use default if null.
 * @return a {@link DateTimeZone} instance for the specified timezone.
 */
public static DateTimeZone getDateTimeZone(final Object zone) {
    if (zone == null)
        return DateTimeZone.getDefault();
    if (zone instanceof DateTimeZone)
        return (DateTimeZone) zone;
    if (zone instanceof TimeZone)
        return getDateTimeZone((TimeZone) zone);
    if (ObjectUtils.isAny(zone.getClass(), Byte.class, Short.class, Integer.class, Long.class))
        return getDateTimeZone(NumberUtils.valueOf(zone.toString(), Long.class));
    if (zone instanceof String)
        return getDateTimeZone(zone.toString());

    return DateTimeZone.UTC;
}

From source file:jp.furplag.util.Localizer.java

License:Apache License

private static DateTimeZone getDateTimeZone(final String zone) {
    if (zone == null)
        return DateTimeZone.getDefault();
    if (StringUtils.isSimilarToBlank(zone))
        return DateTimeZone.UTC;
    if (DateTimeZone.getAvailableIDs().contains(zone))
        return DateTimeZone.forID(zone.toString());
    if (LazyInitializer.ZONE_DUPRECATED.containsKey(zone))
        return DateTimeZone.forTimeZone(TimeZone.getTimeZone(LazyInitializer.ZONE_DUPRECATED.get(zone)));
    if (LazyInitializer.AVAILABLE_ZONE_IDS.contains(zone))
        return DateTimeZone.forTimeZone(TimeZone.getTimeZone(zone));
    Matcher base = OFFSET.matcher(StringUtils.normalize(zone, true));
    if (base.find()) {
        String offsetString = base.group();

        int[] offsetTime = JSONifier.parseLazy(
                JSONifier.stringifyLazy(StringUtils.truncateFirst(offsetString, "[\\+\\-]").split("[:\\.]")),
                int[].class);
        if (offsetTime.length < 1)
            return DateTimeZone.UTC;
        LocalTime offset = new LocalTime(offsetTime.length > 0 ? offsetTime[0] : 0,
                offsetTime.length > 1 ? offsetTime[1] : 0, offsetTime.length > 2 ? offsetTime[2] : 0,
                offsetTime.length > 3 ? offsetTime[3] : 0);

        return DateTimeZone.forID((offsetString.startsWith("-") ? "-" : "+") + offset.toString(OFFSET_FORMAT));
    }//from  w  ww. ja  v  a  2  s. c om

    return DateTimeZone.UTC;
}

From source file:jp.furplag.util.Localizer.java

License:Apache License

private static DateTimeZone getDateTimeZone(final TimeZone zone) {
    if (zone == null)
        return DateTimeZone.getDefault();
    String zoneID = ((TimeZone) zone).getID();
    if (DateTimeZone.getAvailableIDs().contains(zoneID))
        return DateTimeZone.forID(zoneID);
    if (LazyInitializer.ZONE_DUPRECATED.containsKey(zoneID))
        return DateTimeZone.forTimeZone(TimeZone.getTimeZone(LazyInitializer.ZONE_DUPRECATED.get(zoneID)));

    return DateTimeZone.forTimeZone((TimeZone) zone);
}

From source file:jp.furplag.util.Localizer.java

License:Apache License

private static DateTimeZone getDateTimeZone(final Long millis) {
    if (millis == null)
        return DateTimeZone.getDefault();
    if (millis % 86400000L == 0)
        return DateTimeZone.UTC;
    LocalTime offset = LocalTime.fromMillisOfDay((millis % 86400000L) * (millis < 0 ? -1 : 1));

    return DateTimeZone.forID((millis < 0 ? "-" : "+") + offset.toString(OFFSET_FORMAT));
}

From source file:jp.furplag.util.time.DateTimeUtils.java

License:Apache License

public static boolean isToday(final Object then) {
    return isSameDay(then, DateTime.now(), DateTimeZone.getDefault());
}

From source file:jp.furplag.util.time.JodaPrettifier.java

License:Apache License

/**
 * Shorthand for {@link #prettify(Object, Object, Locale, DateTimeZone, Object)}.
 *
 * @param then the datetime object, null means current date-time.
 * @param reference the moment of a starting point ( {@link org.joda.time.ReadableInstant} and {@link Long} specifiable ). Use {@code DateTime.now()} as a start point if {@code reference} is null.
 * @return {@code prettify(then, null, Locale.getDefault(), DateTimeZone.getDefault(), null)}.
 *///from  w ww . jav  a 2  s  . c  om
public static String prettify(final Object then, final Object reference) {
    return prettify(then, reference, Locale.getDefault(), DateTimeZone.getDefault(), null);
}