Search in sources :

Example 16 with DateTimeFormatterBuilder

use of org.joda.time.format.DateTimeFormatterBuilder in project h2o-2 by h2oai.

the class ParseTime method listTimezones.

public static String listTimezones() {
    DateTimeFormatter offsetFormatter = new DateTimeFormatterBuilder().appendTimeZoneOffset(null, true, 2, 4).toFormatter();
    Set<String> idSet = DateTimeZone.getAvailableIDs();
    Map<String, String> tzMap = new TreeMap();
    Iterator<String> it = idSet.iterator();
    String id, cid, offset, key, output;
    DateTimeZone tz;
    int i = 0;
    long millis = System.currentTimeMillis();
    // collect canonical and alias IDs into a map
    while (it.hasNext()) {
        id = it.next();
        tz = DateTimeZone.forID(id);
        cid = tz.getID();
        offset = offsetFormatter.withZone(tz).print(tz.getStandardOffset(millis));
        key = offset + " " + cid;
        if (id == cid) {
            // Canonical ID
            if (!tzMap.containsKey(key))
                tzMap.put(key, "");
        } else {
            // alias ID
            if (!tzMap.containsKey(key))
                tzMap.put(key, id);
            else
                tzMap.put(key, tzMap.get(key) + ", " + id);
        }
    }
    // assemble result
    output = "StandardOffset CanonicalID, Aliases\n";
    for (Map.Entry<String, String> e : tzMap.entrySet()) output += e.getKey() + e.getValue() + "\n";
    return output;
}
Also used : ValueString(water.parser.ValueString) TreeMap(java.util.TreeMap) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) TreeMap(java.util.TreeMap) Map(java.util.Map) DateTimeFormatterBuilder(org.joda.time.format.DateTimeFormatterBuilder) DateTimeZone(org.joda.time.DateTimeZone)

Example 17 with DateTimeFormatterBuilder

use of org.joda.time.format.DateTimeFormatterBuilder in project h2o-3 by h2oai.

the class ParseTime method forStrptimePattern.

/**
   * Factory to create a formatter from a strptime pattern string.
   * This models the commonly supported features of strftime from POSIX
   * (where it can).
   * <p>
   * The format may contain locale specific output, and this will change as
   * you change the locale of the formatter.
   * Call DateTimeFormatter.withLocale(Locale) to switch the locale.
   * For example:
   * <pre>
   * DateTimeFormat.forPattern(pattern).withLocale(Locale.FRANCE).print(dt);
   * </pre>
   *
   * @param pattern  pattern specification
   * @return the formatter
   *  @throws IllegalArgumentException if the pattern is invalid
   */
public static DateTimeFormatter forStrptimePattern(String pattern) {
    if (pattern == null || pattern.length() == 0)
        throw new IllegalArgumentException("Empty date time pattern specification");
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    parseToBuilder(builder, pattern);
    DateTimeFormatter formatter = builder.toFormatter();
    return formatter;
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeFormatterBuilder(org.joda.time.format.DateTimeFormatterBuilder)

Example 18 with DateTimeFormatterBuilder

use of org.joda.time.format.DateTimeFormatterBuilder in project uPortal by Jasig.

the class BaseStatisticsReportController method initBinder.

@InitBinder
public void initBinder(WebDataBinder binder) {
    final DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern("M/d/yyyy").toFormatter();
    binder.registerCustomEditor(DateMidnight.class, new CustomDateMidnightEditor(formatter, false));
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeFormatterBuilder(org.joda.time.format.DateTimeFormatterBuilder) InitBinder(org.springframework.web.bind.annotation.InitBinder)

Aggregations

DateTimeFormatterBuilder (org.joda.time.format.DateTimeFormatterBuilder)18 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)17 DateTimeParser (org.joda.time.format.DateTimeParser)8 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 DateTimeZone (org.joda.time.DateTimeZone)2 InitBinder (org.springframework.web.bind.annotation.InitBinder)2 PrestoException (com.facebook.presto.spi.PrestoException)1 FormatDateTimeFormatter (org.elasticsearch.common.joda.FormatDateTimeFormatter)1 ValueString (water.parser.ValueString)1