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:com.facebook.presto.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()) {
                batch.execute();/*from  ww  w.  j av a2s.  co  m*/
                return;
            }
            PreparedBatchPart part = batch.add();
            for (int column = 0; column < columns.size(); column++) {
                Type type = columns.get(column).getType();
                if (BOOLEAN.equals(type)) {
                    part.bind(column, cursor.getBoolean(column));
                } else if (BIGINT.equals(type)) {
                    part.bind(column, cursor.getLong(column));
                } else if (INTEGER.equals(type)) {
                    part.bind(column, (int) cursor.getLong(column));
                } else if (DOUBLE.equals(type)) {
                    part.bind(column, cursor.getDouble(column));
                } else if (type instanceof VarcharType) {
                    part.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);
                    part.bind(column, new Date(localMillis));
                } else {
                    throw new IllegalArgumentException("Unsupported type " + type);
                }
            }
        }
        batch.execute();
    }
}

From source file:com.flooose.gpxkeeper.GPXFile.java

License:Open Source License

public void saveTrackingPointAsJSON() {
    DateTime timestamp = null;// ww w  .  j  a  va 2 s  .co  m

    JSONObject trackingPoint = new JSONObject();

    for (int i = 0; i < parser.getAttributeCount(); i++) {
        try {
            if ("lon".equals(parser.getAttributeName(i))) {
                trackingPoint.put(LONGITUDE, parser.getAttributeValue(i));

            } else if ("lat".equals(parser.getAttributeName(i))) {
                trackingPoint.put(LATITUDE, parser.getAttributeValue(i));
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    try {
        while (!trackPointEnd()) {
            if ("ele".equals(parser.getName()) && parser.getEventType() != parser.END_TAG) {
                while (parser.getEventType() != parser.TEXT)
                    parser.next();
                trackingPoint.put(GPXFile.ELEVATION, parser.getText());
            } else if ("time".equals(parser.getName()) && parser.getEventType() != parser.END_TAG) {
                while (parser.getEventType() != parser.TEXT)
                    parser.next();
                DateTimeFormatter dtf = DateTimeFormat.forPattern(GPX_DATE_FORMAT_STRING);
                timestamp = dtf.withZoneUTC().parseDateTime(parser.getText());

                if (startTime == null) {
                    startTime = timestamp.withZone(DateTimeZone.getDefault());

                    gpsActivity.put(GPXFile.START_TIME,
                            new SimpleDateFormat(DATE_FORMAT_STRING).format(startTime.getMillis()));
                }
            }
            parser.next();
        }
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    try {
        trackingPoint.put(GPXFile.TIMESTAMP, (timestamp.getMillis() - startTime.getMillis()) / 1000); // there should be a constant defined somewhere. Find it.
        trackingPoint.put(GPXFile.TRACKING_POINT_TYPE, "gps");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    gpsPath.put(trackingPoint);
}

From source file:com.foundationdb.server.service.config.ConfigurationServiceImpl.java

License:Open Source License

private void validateTimeZone() {
    String timezone = System.getProperty("user.timezone");
    // The goal here is to make sure that if the user sets user.timezone we will parse it correctly and not end up
    // in a situation where DateTimeZone is inconsistent with TimeZone, or where it just defaulted to UTC because
    // the user did "-Duser.timezone=America/Los_angeles" (note the lower case a).
    // There are other cases where it would work, such as "-Duser.timezone=PST", but PST isn't a valid timezone
    // according to DateTimeZone, so we will stop, even though it would technically work. That's ok though, because
    // PST is just there for java 1.1.x compatibility.

    // Note also that in the open jdk for 1.7u and 1.8 (at least) there's a bug on Mac OS X where if you specify
    // an invalid user.timezone, it will end up being GMT}05:00 where the 05:00 is your system time, and the } is
    // an unprintable character. I filed a bug though, so that might get fixed.

    // Also note, that, as of this writing, there are usages of both java.util date functionality and Joda
    if (timezone != null && timezone.length() != 0 && DateTimeZone.getProvider().getZone(timezone) == null) {
        // Originally a hard error but JRE on CentOS 6 found to consistently misuse /etc/sysconfig/clock
        // throw new InvalidTimeZoneException();
        LOG.error("Reverting to timezone {} as Joda does not support user.timezone={}",
                DateTimeZone.getDefault(), timezone);
    } else {/* w  w w. j  a  v a  2s.  co m*/
        LOG.debug("Using timezone: {}", DateTimeZone.getDefault());
    }
}

From source file:com.foundationdb.server.types.mcompat.mtypes.MTypesTranslator.java

License:Open Source License

@Override
public void setTimestampMillisValue(ValueTarget value, long millis, int nanos) {
    TClass tclass = TInstance.tClass(value.getType());
    if (tclass == MDateAndTime.DATE) {
        value.putInt32(MDateAndTime.encodeDate(millis, DateTimeZone.getDefault().getID()));
    } else if (tclass == MDateAndTime.TIME) {
        value.putInt32(MDateAndTime.encodeTime(millis, DateTimeZone.getDefault().getID()));
    } else if (tclass == MDateAndTime.DATETIME) {
        value.putInt64(MDateAndTime.encodeDateTime(millis, DateTimeZone.getDefault().getID()));
    } else {//from   w  ww. j  a v a 2  s. co m
        value.putInt32((int) (millis / 1000));
    }
}

From source file:com.foundationdb.server.types.TExecutionContext.java

License:Open Source License

/**
 * Some functions need to get the current timezone (session/global), not the JVM's timezone.
 * @return  the server's timezone.//from w w  w.j a  v  a 2  s .  c o m
 */
public String getCurrentTimezone() {
    // TODO need to get this from the session
    return DateTimeZone.getDefault().getID();
}

From source file:com.foundationdb.server.types.TPreptimeContext.java

License:Open Source License

public String getCurrentTimezone() {
    // TODO need to get this from the session
    return DateTimeZone.getDefault().getID();
}

From source file:com.foundationdb.sql.server.ServerValueDecoder.java

License:Open Source License

private static long seconds2000NoTZ(long secs) {
    long millis = (secs + 946684800) * 1000; // 2000-01-01 00:00:00-UTC.
    DateTimeZone dtz = DateTimeZone.getDefault();
    millis -= dtz.getOffset(millis);/* w  ww  .  j  ava 2  s. c om*/
    return millis;
}

From source file:com.foundationdb.sql.server.ServerValueEncoder.java

License:Open Source License

/** Adjust milliseconds since 1970-01-01 00:00:00-UTC to seconds since
 * 2000-01-01 00:00:00 timezoneless. A conversion from local time
 * to UTC involves an offset that varies for Summer time. A
 * conversion from local time to timezoneless just removes the
 * zone as though all days were the same length.
 *//*from  w  w w  .j  a v a 2 s . com*/
private static long seconds2000NoTZ(long millis) {
    DateTimeZone dtz = DateTimeZone.getDefault();
    millis += dtz.getOffset(millis);
    return millis / 1000 - 946684800; // 2000-01-01 00:00:00-UTC.
}

From source file:com.github.markserrano.jsonquery.jpa.util.DateTimeZoneRule.java

License:Apache License

private void before() {
    oldTimeZone = DateTimeZone.getDefault();
    DateTimeZone.setDefault(zone);
}

From source file:com.hmsinc.epicenter.surveillance.notification.EventNotifierUtils.java

License:Open Source License

public static String getTemplate(final Event event, final EpiCenterUser user, final String templateName,
        final String encoding, final String url, final VelocityEngine velocityEngine) {

    Map<String, Object> context = new HashMap<String, Object>();
    context.put("date", new DateTimeFormatTool());
    context.put("number", new NumberTool());
    context.put("event", event);
    context.put("user", user);

    context.put("locale", Locale.getDefault());
    context.put("timezone", DateTimeZone.getDefault());

    if (event instanceof Anomaly) {

        Anomaly anomaly = (Anomaly) event;

        context.put("analysisStartTime", anomaly.getAnalysisTimestamp().minusDays(1));
        context.put("predictedObservedValueDouble", anomaly.getPredictedObservedValue());
        context.put("epicenterUrl", url);

        context.put("attributes", makeAgeGroupAndGenderString(anomaly));
    }/*from  w w w.  j  a v  a 2  s  .c om*/
    return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateName, encoding, context);
}