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;
}
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;
}
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));
}
Aggregations