Example usage for org.joda.time DateTimeZone forID

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

Introduction

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

Prototype

@FromString
public static DateTimeZone forID(String id) 

Source Link

Document

Gets a time zone instance for the specified time zone id.

Usage

From source file:io.druid.sql.calcite.planner.PlannerContext.java

License:Apache License

public static PlannerContext create(final DruidOperatorTable operatorTable, final ExprMacroTable macroTable,
        final PlannerConfig plannerConfig, final Map<String, Object> queryContext) {
    final DateTime utcNow;
    final DateTimeZone timeZone;

    if (queryContext != null) {
        final Object tsParam = queryContext.get(CTX_SQL_CURRENT_TIMESTAMP);
        final Object tzParam = queryContext.get(CTX_SQL_TIME_ZONE);

        if (tsParam != null) {
            utcNow = new DateTime(tsParam, DateTimeZone.UTC);
        } else {// w  w  w  .j  a  v  a2 s.c o m
            utcNow = new DateTime(DateTimeZone.UTC);
        }

        if (tzParam != null) {
            timeZone = DateTimeZone.forID(String.valueOf(tzParam));
        } else {
            timeZone = DateTimeZone.UTC;
        }
    } else {
        utcNow = new DateTime(DateTimeZone.UTC);
        timeZone = DateTimeZone.UTC;
    }

    return new PlannerContext(operatorTable, macroTable, plannerConfig.withOverrides(queryContext),
            utcNow.withZone(timeZone), queryContext);
}

From source file:io.prestosql.jdbc.PrestoResultSet.java

License:Apache License

PrestoResultSet(StatementClient client, long maxRows, Consumer<QueryStats> progressCallback,
        WarningsManager warningsManager) throws SQLException {
    this.client = requireNonNull(client, "client is null");
    requireNonNull(progressCallback, "progressCallback is null");

    this.sessionTimeZone = DateTimeZone.forID(client.getTimeZone().getId());
    this.queryId = client.currentStatusInfo().getId();

    List<Column> columns = getColumns(client, progressCallback);
    this.fieldMap = getFieldMap(columns);
    this.columnInfoList = getColumnInfo(columns);
    this.resultSetMetaData = new PrestoResultSetMetaData(columnInfoList);
    this.warningsManager = requireNonNull(warningsManager, "warningsManager is null");

    this.results = flatten(new ResultsPageIterator(client, progressCallback, warningsManager), maxRows);
}

From source file:io.prestosql.plugin.hive.benchmark.FileFormat.java

License:Apache License

private static ConnectorPageSource createPageSource(HiveRecordCursorProvider cursorProvider,
        ConnectorSession session, File targetFile, List<String> columnNames, List<Type> columnTypes,
        HiveStorageFormat format) {/*from w  w w.java 2  s  . com*/
    List<HiveColumnHandle> columnHandles = new ArrayList<>(columnNames.size());
    TypeTranslator typeTranslator = new HiveTypeTranslator();
    for (int i = 0; i < columnNames.size(); i++) {
        String columnName = columnNames.get(i);
        Type columnType = columnTypes.get(i);
        columnHandles.add(new HiveColumnHandle(columnName, toHiveType(typeTranslator, columnType),
                columnType.getTypeSignature(), i, REGULAR, Optional.empty()));
    }

    RecordCursor recordCursor = cursorProvider.createRecordCursor(conf, session,
            new Path(targetFile.getAbsolutePath()), 0, targetFile.length(), targetFile.length(),
            createSchema(format, columnNames, columnTypes), columnHandles, TupleDomain.all(),
            DateTimeZone.forID(session.getTimeZoneKey().getId()), TYPE_MANAGER, false).get();
    return new RecordPageSource(columnTypes, recordCursor);
}

From source file:io.prestosql.plugin.hive.benchmark.FileFormat.java

License:Apache License

private static ConnectorPageSource createPageSource(HivePageSourceFactory pageSourceFactory,
        ConnectorSession session, File targetFile, List<String> columnNames, List<Type> columnTypes,
        HiveStorageFormat format) {/*from  ww  w .j av  a  2  s. c  o m*/
    List<HiveColumnHandle> columnHandles = new ArrayList<>(columnNames.size());
    TypeTranslator typeTranslator = new HiveTypeTranslator();
    for (int i = 0; i < columnNames.size(); i++) {
        String columnName = columnNames.get(i);
        Type columnType = columnTypes.get(i);
        columnHandles.add(new HiveColumnHandle(columnName, toHiveType(typeTranslator, columnType),
                columnType.getTypeSignature(), i, REGULAR, Optional.empty()));
    }

    return pageSourceFactory.createPageSource(conf, session, new Path(targetFile.getAbsolutePath()), 0,
            targetFile.length(), targetFile.length(), createSchema(format, columnNames, columnTypes),
            columnHandles, TupleDomain.all(), DateTimeZone.forID(session.getTimeZoneKey().getId())).get();
}

From source file:io.soliton.protobuf.TimeServer.java

License:Apache License

@Override
public ListenableFuture<TimeResponse> getTime(TimeRequest request) {
    DateTimeZone timeZone = DateTimeZone.forID(request.getTimezone());
    DateTime now = new DateTime(timeZone);
    TimeResponse.Builder response = TimeResponse.newBuilder();
    return Futures.immediateFuture(response.setTime(now.getMillis()).build());
}

From source file:io.soliton.time.TimeClient.java

License:Apache License

public static void main(String... args) throws Exception {
    // Parse arguments
    TimeClient timeClient = new TimeClient();
    new JCommander(timeClient, args);

    // Create client
    QuartzClient.Builder clientBuilder = QuartzClient
            .newClient(HostAndPort.fromParts(timeClient.hostname, timeClient.port));

    if (timeClient.ssl) {
        clientBuilder.setSslContext(getSslContext());
    }/* ww w  .  j ava  2  s . c o  m*/

    QuartzClient client = clientBuilder.build();

    // Create service stub
    Time.TimeService.Interface timeService = Time.TimeService.newStub(client);

    CountDownLatch latch = new CountDownLatch(DateTimeZone.getAvailableIDs().size());

    // For each known timezone, request its current local time.
    for (String timeZoneId : DateTimeZone.getAvailableIDs()) {
        DateTimeZone timeZone = DateTimeZone.forID(timeZoneId);
        Time.TimeRequest request = Time.TimeRequest.newBuilder().setTimezone(timeZoneId).build();
        Futures.addCallback(timeService.getTime(request), new Callback(latch, timeZone), EXECUTOR);
    }

    latch.await();
    client.close();
}

From source file:io.soliton.time.TimeServer.java

License:Apache License

@Override
public ListenableFuture<Time.TimeResponse> getTime(Time.TimeRequest request) {
    DateTimeZone timeZone = DateTimeZone.forID(request.getTimezone());
    DateTime now = new DateTime(timeZone);
    Time.TimeResponse.Builder response = Time.TimeResponse.newBuilder();
    return Futures.immediateFuture(response.setTime(now.getMillis()).build());
}

From source file:io.spikex.core.helper.Variables.java

License:Apache License

public static DateTime createDateTimeNow(final String var) {

    DateTime dt;/* w ww  . j  a v  a2  s.  c  o m*/

    // #now
    // #now(UTC)
    // #now(UTC,0h,-10m,0s)
    // #now(0h,-10m,0s)
    // #now(30m)
    Matcher m = REGEXP_NOW.matcher(var);
    //
    // Timezone
    //
    String tz = null;
    boolean found = m.find();
    if (found) {
        tz = m.group(1);
    }
    //
    // Hours
    //
    int hours = 0;
    if (found) {
        String val = m.group(2);
        if (val != null) {
            hours = Integer.parseInt(val.substring(0, val.length() - 1));
        }
    }
    //
    // Minutes
    //
    int mins = 0;
    if (found) {
        String val = m.group(3);
        if (val != null) {
            mins = Integer.parseInt(val.substring(0, val.length() - 1));
        }
    }
    //
    // Seconds
    //
    int secs = 0;
    if (found) {
        String val = m.group(4);
        if (val != null) {
            secs = Integer.parseInt(val.substring(0, val.length() - 1));
        }
    }

    System.out.println("var: " + var + " tz: " + tz + " hours: " + hours + " mins: " + mins + " secs: " + secs);

    if (tz != null) {
        dt = new DateTime(DateTimeZone.forID(tz));
    } else {
        dt = new DateTime();
    }

    dt = dt.plusHours(hours);
    dt = dt.plusMinutes(mins);
    dt = dt.plusSeconds(secs);

    return dt;
}

From source file:io.spikex.core.util.CronEntry.java

License:Apache License

public static CronEntry create(final String def) {
    CronEntry entry = new CronEntry(def);
    Matcher m = REGEXP_ENTRY.matcher(def);
    boolean everyMinute = true;
    ////from www  .  j  a  v a 2s.  com
    // 1. Minute field
    //
    if (!m.find()) {
        throw new IllegalArgumentException("Could not find minute field: " + def);
    }
    entry.m_minutes = parseField(m.group(), 0, 59, entry.m_minutes, null);
    if (entry.m_minutes[0] != -1) {
        everyMinute = false;
    }
    //
    // 2. Hour field
    //
    if (!m.find()) {
        throw new IllegalArgumentException("Could not find hour field: " + def);
    }
    entry.m_hours = parseField(m.group(), 0, 23, entry.m_hours, null);
    if (entry.m_hours[0] != -1) {
        everyMinute = false;
    }
    //
    // 3. Day of month field
    //
    if (!m.find()) {
        throw new IllegalArgumentException("Could not find day of month field: " + def);
    }
    entry.m_days = parseField(m.group(), 1, 31, entry.m_days, null);
    if (entry.m_days[0] != -1) {
        everyMinute = false;
        entry.m_isEveryDay = false;
    }
    //
    // 4. Month field
    //
    if (!m.find()) {
        throw new IllegalArgumentException("Could not find month field: " + def);
    }
    entry.m_months = parseField(m.group(), 1, 12, entry.m_months, TAG_MONTHS);
    if (entry.m_months[0] != -1) {
        everyMinute = false;
    }
    //
    // 5. Day of week field
    //
    if (!m.find()) {
        throw new IllegalArgumentException("Could not find month field: " + def);
    }
    entry.m_dows = parseField(m.group(), 1, 7, entry.m_dows, TAG_DOWS);
    if (entry.m_dows[0] != -1) {
        everyMinute = false;
        entry.m_isEveryDow = false;
    }
    //
    // 6. Timezone
    //
    if (m.find()) {
        String tz = m.group();
        // Sanity check (throws an exception if unknown timezone)
        DateTimeZone.forID(tz);
        entry.m_timezone = tz;
    }

    entry.m_isEveryMinute = everyMinute;
    return entry;
}

From source file:io.spikex.filter.Limit.java

License:Apache License

@Override
protected void handleEvent(final JsonObject event) {
    ///*from   www.  ja  v  a 2s. co  m*/
    // Find matching rule
    //
    boolean match = false;
    String throttle = "";
    DateTime now = null;
    String timezone = "";
    boolean discardOnMismatch = m_discardOnMismatch;
    Map<String, CronEntry> schedules = m_schedules;
    List<Rule> rules = m_rules;
    for (Rule rule : rules) {
        //
        // Matching schedule?
        //
        CronEntry entry = schedules.get(rule.getSchedule());
        if (!timezone.equals(entry.getTimezone())) {
            timezone = entry.getTimezone();
            now = DateTime.now(DateTimeZone.forID(timezone));
        }
        if (entry.isDefined(now)) {

            // schedule matched, now match against rule
            throttle = rule.getAction();

            try {
                // Match against tag and/or field value
                logger().trace("Evaluating rule: {}", rule);
                match = rule.match(event);
            } catch (NumberFormatException e) {
                logger().error("Failed to match rule", e);
                match = false;
            }
        }
    }
    // Throttle only if we had a match
    if (match) {
        throttleEvent(event, throttle);
    } else {
        if (!discardOnMismatch) {
            emitEvent(event);
        }
    }
}