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:com.lowzj.connect.aliyun.oss.TopicPartitionWriter.java

License:Apache License

TopicPartitionWriter(TopicPartition tp, RecordWriterProvider<AliyunOSSSinkConnectorConfig> writerProvider,
        Partitioner<FieldSchema> partitioner, AliyunOSSSinkConnectorConfig connectorConfig,
        SinkTaskContext context, Time time) {
    this.time = time;
    this.tp = tp;
    this.context = context;
    this.writerProvider = writerProvider;
    this.partitioner = partitioner;

    flushSize = connectorConfig.getInt(AliyunOSSSinkConnectorConfig.FLUSH_SIZE_CONFIG);
    topicsDir = connectorConfig.getString(StorageCommonConfig.TOPICS_DIR_CONFIG);
    rotateIntervalMs = connectorConfig.getLong(AliyunOSSSinkConnectorConfig.ROTATE_INTERVAL_MS_CONFIG);
    rotateScheduleIntervalMs = connectorConfig
            .getLong(AliyunOSSSinkConnectorConfig.ROTATE_SCHEDULE_INTERVAL_MS_CONFIG);
    timeoutMs = connectorConfig.getLong(AliyunOSSSinkConnectorConfig.RETRY_BACKOFF_CONFIG);
    compatibility = StorageSchemaCompatibility
            .getCompatibility(connectorConfig.getString(HiveConfig.SCHEMA_COMPATIBILITY_CONFIG));

    buffer = new LinkedList<>();
    commitFiles = new HashMap<>();
    writers = new HashMap<>();
    currentSchemas = new HashMap<>();
    startOffsets = new HashMap<>();
    state = State.WRITE_STARTED;/*from  w w w  .  j a v a 2s  .  com*/
    failureTime = -1L;
    currentOffset = -1L;
    dirDelim = connectorConfig.getString(StorageCommonConfig.DIRECTORY_DELIM_CONFIG);
    fileDelim = connectorConfig.getString(StorageCommonConfig.FILE_DELIM_CONFIG);
    extension = writerProvider.getExtension();
    zeroPadOffsetFormat = "%0"
            + connectorConfig.getInt(AliyunOSSSinkConnectorConfig.FILENAME_OFFSET_ZERO_PAD_WIDTH_CONFIG) + "d";

    timezone = rotateScheduleIntervalMs > 0
            ? DateTimeZone.forID(connectorConfig.getString(PartitionerConfig.TIMEZONE_CONFIG))
            : null;

    // Initialize rotation timers
    updateRotationTimers();
}

From source file:com.marklogic.samplestack.web.QnADocumentController.java

License:Apache License

/** 
 * Searches for QnADocuments and returns search results to request body
 * @param q A search string (See Search API docs)
 * @param start The index of the first return result.
 * @return A Search API JSON response containing matches, facets and snippets.
 *///  w  w  w.j  a v  a 2 s . com
@RequestMapping(value = "v1/questions", method = RequestMethod.GET)
public @ResponseBody JsonNode getQnADocuments(@RequestParam(required = false) String q,
        @RequestParam(required = false, defaultValue = "1") long start) {
    if (q == null) {
        q = "sort:active";
    }
    ObjectNode combinedQuery = mapper.createObjectNode();
    ObjectNode qtext = combinedQuery.putObject("search");
    qtext.put("qtext", q);
    return qnaService.rawSearch(ClientRole.securityContextRole(), combinedQuery, start,
            DateTimeZone.forID("US/Pacific"));
}

From source file:com.marklogic.samplestack.web.QnADocumentController.java

License:Apache License

/**
 * Exposes an endpoint for searching QnADocuments.
 * @param combinedQuery A JSON combined query.
 * @param start The index of the first result to return.
 * @return A Search Results JSON response.
 *//*from w w  w . ja va  2 s. c  om*/
@RequestMapping(value = "v1/search", method = RequestMethod.POST)
public @ResponseBody JsonNode search(@RequestBody ObjectNode combinedQuery,
        @RequestParam(defaultValue = "1", required = false) long start) {

    ObjectNode combinedQueryObject = (ObjectNode) combinedQuery.get("search");
    if (combinedQueryObject == null) {
        throw new SamplestackSearchException("A Samplestack search must have payload with root key \"search\"");
    }
    JsonNode postedStartNode = combinedQueryObject.get("start");
    if (postedStartNode != null) {
        start = postedStartNode.asLong();
        combinedQueryObject.remove("start");
    }
    JsonNode postedTimeZone = combinedQueryObject.get("timezone");
    DateTimeZone userTimeZone = DateTimeZone.getDefault();
    if (postedTimeZone != null) {
        try {
            userTimeZone = DateTimeZone.forID(postedTimeZone.asText());
        } catch (IllegalArgumentException e) {
            throw new SamplestackInvalidParameterException(
                    "Received unrecognized timezone from browser: " + postedTimeZone.asText());
        }
        combinedQueryObject.remove("timezone");
    }
    // TODO review for presence/absense of date facet as performance question.
    return qnaService.rawSearch(ClientRole.securityContextRole(), combinedQuery, start, userTimeZone);
}

From source file:com.metamx.druid.jackson.DefaultObjectMapper.java

License:Open Source License

public DefaultObjectMapper(JsonFactory factory) {
    super(factory);
    SimpleModule serializerModule = new SimpleModule("Druid default serializers", new Version(1, 0, 0, null));
    JodaStuff.register(serializerModule);
    serializerModule.addDeserializer(Granularity.class, new JsonDeserializer<Granularity>() {
        @Override// ww w  .jav a 2 s .  c  o  m
        public Granularity deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
            return Granularity.valueOf(jp.getText().toUpperCase());
        }
    });
    serializerModule.addDeserializer(DateTimeZone.class, new JsonDeserializer<DateTimeZone>() {
        @Override
        public DateTimeZone deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
            String tzId = jp.getText();
            try {
                return DateTimeZone.forID(tzId);
            } catch (IllegalArgumentException e) {
                // also support Java timezone strings
                return DateTimeZone.forTimeZone(TimeZone.getTimeZone(tzId));
            }
        }
    });
    serializerModule.addSerializer(DateTimeZone.class, new JsonSerializer<DateTimeZone>() {
        @Override
        public void serialize(DateTimeZone dateTimeZone, JsonGenerator jsonGenerator,
                SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
            jsonGenerator.writeString(dateTimeZone.getID());
        }
    });
    serializerModule.addSerializer(Sequence.class, new JsonSerializer<Sequence>() {
        @Override
        public void serialize(Sequence value, final JsonGenerator jgen, SerializerProvider provider)
                throws IOException, JsonProcessingException {
            jgen.writeStartArray();
            value.accumulate(null, new Accumulator() {
                @Override
                public Object accumulate(Object o, Object o1) {
                    try {
                        jgen.writeObject(o1);
                    } catch (IOException e) {
                        throw Throwables.propagate(e);
                    }
                    return o;
                }
            });
            jgen.writeEndArray();
        }
    });
    serializerModule.addSerializer(ByteOrder.class, ToStringSerializer.instance);
    serializerModule.addDeserializer(ByteOrder.class, new JsonDeserializer<ByteOrder>() {
        @Override
        public ByteOrder deserialize(JsonParser jp, DeserializationContext ctxt)
                throws IOException, JsonProcessingException {
            if (ByteOrder.BIG_ENDIAN.toString().equals(jp.getText())) {
                return ByteOrder.BIG_ENDIAN;
            }
            return ByteOrder.LITTLE_ENDIAN;
        }
    });
    registerModule(serializerModule);

    configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS, false);
    configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, false);
    configure(SerializationConfig.Feature.INDENT_OUTPUT, false);
}

From source file:com.money.manager.ex.investment.morningstar.MorningstarPriceUpdater.java

License:Open Source License

/**
 * Parse Morningstar response into price information.
 * @param symbol Morningstar symbol//from   w  ww. ja va 2 s .c o m
 * @param html Result
 * @return An object containing price details
 */
private PriceDownloadedEvent parse(String symbol, String html) {
    Document doc = Jsoup.parse(html);

    // symbol
    String yahooSymbol = symbolConverter.getYahooSymbol(symbol);

    // price
    String priceString = doc.body().getElementById("last-price-value").text();
    Money price = MoneyFactory.fromString(priceString);
    // currency
    String currency = doc.body().getElementById("curency").text();
    if (currency.equals("GBX")) {
        price = price.divide(100, MoneyFactory.MAX_ALLOWED_PRECISION);
    }

    // date
    String dateString = doc.body().getElementById("asOfDate").text();
    DateTimeFormatter formatter = DateTimeFormat.forPattern("MM/dd/YYYY HH:mm:ss");
    // the time zone is EST
    DateTime date = formatter.withZone(DateTimeZone.forID("America/New_York")).parseDateTime(dateString)
            .withZone(DateTimeZone.forID("Europe/Vienna"));

    // todo: should this be converted to the exchange time?

    return new PriceDownloadedEvent(yahooSymbol, price, date);
}

From source file:com.moosemorals.weather.LocationFetcherIT.java

License:Open Source License

@Test
public void basics() throws Exception {
    FetchResult result = new LocationFetcher.Builder().setApiKey(apiKey).setQuery("NE6").build().fetch();

    assertNotNull(result, "Result should not be null");

    requestsPerDay = result.getRequestsPerDay();
    requestsPerSecond = result.getRequestsPerSecond();

    assertEquals(result.getError(), null, "Error should be null");
    assertEquals(result.getWeather(), null, "Weather should be null");

    LocationReport report = result.getLocation();
    assertNotNull(report, "Report should not be null");

    assertEquals(report.getLocations().size(), 10);

    Location location = report.getLocations().get(0);

    assertEquals(location.getName(), "Walkergate");
    assertEquals(location.getRegion(), "Tyne and Wear");
    assertEquals(location.getCountry(), "United Kingdom");
    assertEquals(location.getPopulation(), 0);
    assertEquals(location.getLatitude(), 54.974, 0.1);
    assertEquals(location.getLongitude(), -1.572, 0.1);

    // This one changes with local time. Poop.
    DateTimeZone London = DateTimeZone//  w w  w .  j a  v  a  2s.com
            .forOffsetMillis(DateTimeZone.forID("Europe/London").getOffset(new DateTime()));

    assertEquals(location.getTimezone(), London);
}

From source file:com.moss.maven.util.MavenPomPropertiesDateFormatter.java

License:Open Source License

public DateTime parseDateTime(String mavenFormattedDateAndTime) {

    // THE JODA PARSER DOESN'T HANDLE TIMEZONES WELL, SO WE'RE PULLING THE ZONE OUT AND PARSING IT SEPARATELY
    int length = mavenFormattedDateAndTime.length();
    String timezoneText = mavenFormattedDateAndTime.substring(length - 8, length - 5).trim();
    String yearText = mavenFormattedDateAndTime.substring(length - 4).trim();
    String jodaParseableText = mavenFormattedDateAndTime.substring(0, length - 8).trim() + " " + yearText;

    // PARSE THE ZONE
    DateTimeZone timeZone;//from w  w w  .  jav  a 2s.  c om
    if ("EDT".equals(timezoneText))
        timeZone = DateTimeZone.forID("America/New_York");
    else
        timeZone = DateTimeZone.forID(timezoneText);

    // PARSE THE STRING WITHOUT THE ZONE INFO
    DateTimeFormatter fmt = DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss YYYY");
    DateTime dateTime = fmt.parseDateTime(jodaParseableText);

    // ADD THE ZONE BACK
    dateTime = new DateTime(dateTime.getMillis(), timeZone);

    return dateTime;
}

From source file:com.mycompany.conceptestsring.JodaDateT.java

public static void main(String[] arg) {
    DateTime dt = new DateTime();

    DateTimeZone dtZone = DateTimeZone.forID("Europe/London");
    System.out.println("dtZone = " + dtZone + " date" + dt.toDateTime(dtZone));
    System.out.println("dt = " + dt + dt.getZone());

}

From source file:com.nesscomputing.mojo.numbers.DateField.java

License:Apache License

@Override
public String getPropertyValue() {
    final DateTimeZone timeZone = dateDefinition.getTimezone() == null ? DateTimeZone.getDefault()
            : DateTimeZone.forID(dateDefinition.getTimezone());

    DateTime date = getDateTime(valueProvider.getValue(), timeZone);

    if (date == null && dateDefinition.getValue() != null) {
        date = new DateTime(dateDefinition.getValue(), timeZone);
    }//  ww  w  .  j av  a2  s. co  m

    if (date == null) {
        date = new DateTime(timeZone);
    }

    final String format = dateDefinition.getFormat();

    if (format == null) {
        return date.toString();
    } else {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(format);
        return formatter.print(date);
    }
}

From source file:com.netflix.iep.config.Strings.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> T cast(Class<T> c, String v) {
    //if (c.isEnum()) return (T) enumValue(c, v);
    if (c == String.class)
        return (T) v;
    if (c == boolean.class)
        return (T) java.lang.Boolean.valueOf(v);
    if (c == byte.class)
        return (T) java.lang.Byte.valueOf(v);
    if (c == short.class)
        return (T) java.lang.Short.valueOf(v);
    if (c == int.class)
        return (T) java.lang.Integer.valueOf(v);
    if (c == long.class)
        return (T) java.lang.Long.valueOf(v);
    if (c == float.class)
        return (T) java.lang.Float.valueOf(v);
    if (c == double.class)
        return (T) java.lang.Double.valueOf(v);
    //if (c == Number.class) return (T) java.lang.Number.valueOf(v);
    if (c == Boolean.class)
        return (T) java.lang.Boolean.valueOf(v);
    if (c == Byte.class)
        return (T) java.lang.Byte.valueOf(v);
    if (c == Short.class)
        return (T) java.lang.Short.valueOf(v);
    if (c == Integer.class)
        return (T) java.lang.Integer.valueOf(v);
    if (c == Long.class)
        return (T) java.lang.Long.valueOf(v);
    if (c == Float.class)
        return (T) java.lang.Float.valueOf(v);
    if (c == Double.class)
        return (T) java.lang.Double.valueOf(v);
    if (c == DateTime.class)
        return (T) parseDate(v);
    if (c == DateTimeZone.class)
        return (T) DateTimeZone.forID(v);
    if (c == Duration.class)
        return (T) parseDuration(v);
    if (c == Period.class)
        return (T) parsePeriod(v);
    if (c == Pattern.class)
        return (T) Pattern.compile(v);
    throw new IllegalArgumentException("unsupported property type " + c.getName());
}