List of usage examples for org.joda.time Period parse
public static Period parse(String str, PeriodFormatter formatter)
From source file:gobblin.metrics.reporter.ScheduledReporter.java
License:Apache License
@VisibleForTesting static int parsePeriodToSeconds(String periodStr) { try {/*from ww w . j a va 2s .com*/ return Period.parse(periodStr.toUpperCase(), PERIOD_FORMATTER).toStandardSeconds().getSeconds(); } catch (ArithmeticException ae) { throw new RuntimeException( String.format("Reporting interval is too long. Max: %d seconds.", Integer.MAX_VALUE)); } }
From source file:microsoft.exchange.webservices.data.core.EwsUtilities.java
License:Open Source License
/** * Takes an xs:duration string as defined by the W3 Consortiums * Recommendation "XML Schema Part 2: Datatypes Second Edition", * http://www.w3.org/TR/xmlschema-2/#duration, and converts it into a * System.TimeSpan structure This method uses the following approximations: * 1 year = 365 days 1 month = 30 days Additionally, it only allows for four * decimal points of seconds precision./*from w w w .ja v a2 s . co m*/ * * @param xsDuration xs:duration string to convert * @return System.TimeSpan structure */ public static TimeSpan getXSDurationToTimeSpan(String xsDuration) { // TODO: Need to check whether this should be the equivalent or not Matcher m = PATTERN_TIME_SPAN.matcher(xsDuration); boolean negative = false; if (m.find()) { negative = true; } // Removing leading '-' if (negative) { xsDuration = xsDuration.replace("-P", "P"); } Period period = Period.parse(xsDuration, ISOPeriodFormat.standard()); long retval = period.toStandardDuration().getMillis(); if (negative) { retval = -retval; } return new TimeSpan(retval); }
From source file:org.apache.hadoop.gateway.config.impl.GatewayConfigImpl.java
License:Apache License
@Override public long getGatewayDeploymentsBackupAgeLimit() { PeriodFormatter f = new PeriodFormatterBuilder().appendDays().toFormatter(); String s = get(DEPLOYMENTS_BACKUP_AGE_LIMIT, "-1"); long d;/*ww w . j a v a2 s . co m*/ try { Period p = Period.parse(s, f); d = p.toStandardDuration().getMillis(); if (d < 0) { d = -1; } } catch (Exception e) { d = -1; } return d; }
From source file:org.apache.hadoop.gateway.config.impl.GatewayConfigImpl.java
License:Apache License
private static long parseNetworkTimeout(String s) { PeriodFormatter f = new PeriodFormatterBuilder().appendMinutes().appendSuffix("m", " min").appendSeconds() .appendSuffix("s", " sec").appendMillis().toFormatter(); Period p = Period.parse(s, f); return p.toStandardDuration().getMillis(); }
From source file:org.apache.hadoop.gateway.dispatch.DefaultHttpClientFactory.java
License:Apache License
private static long parseTimeout(String s) { PeriodFormatter f = new PeriodFormatterBuilder().appendMinutes().appendSuffix("m", " min").appendSeconds() .appendSuffix("s", " sec").appendMillis().toFormatter(); Period p = Period.parse(s, f); return p.toStandardDuration().getMillis(); }
From source file:org.imsglobal.caliper.validators.TimeValidator.java
License:Open Source License
/** * Parses duration string against the standard ISO8601 duration format: PyYmMwWdDThHmMsS. * Note that milliseconds precision is not defined as part of the standard duration format. * @param period/*from ww w .ja va 2s . c om*/ * @return boolean true/false */ private static boolean checkPeriodFormat(String period) { try { Period.parse(period, ISOPeriodFormat.standard()); return true; } catch (IllegalArgumentException ex) { return false; } }
From source file:org.neotree.model.realm.SessionValue.java
License:Open Source License
@SuppressWarnings("unchecked") public <T> T getValue() { switch (getDataTypeAsObject()) { case BOOLEAN: return (T) getBooleanValue(); case DATETIME: case DATE:/*from ww w . j av a2s. co m*/ case TIME: return (T) ((getStringValue() != null) ? DateTime.parse(getStringValue(), ISODateTimeFormat.dateTimeNoMillis()) : null); case ID: return (T) getStringValue(); case NUMBER: return (T) getDoubleValue(); case PERIOD: return (T) ((getStringValue() != null) ? Period.parse(getStringValue(), ISOPeriodFormat.standard()) : null); case SET_ID: return (T) getStringValue(); case STRING: return (T) getStringValue(); case VOID: default: return null; } }
From source file:org.neotree.model.realm.SessionValue.java
License:Open Source License
@JsonIgnore @SuppressWarnings("unchecked") public String getValueAsFormattedString(Context context) { switch (getDataTypeAsObject()) { case BOOLEAN: return (getBooleanValue() != null && getBooleanValue()) ? "Yes" : "No"; case DATETIME: return (getStringValue() == null) ? context.getString(R.string.label_not_set) : DateTime.parse(getStringValue(), ISODateTimeFormat.dateTimeNoMillis()) .toString(NeoTree.NeoTreeFormat.DATETIME); case DATE:/*from w w w .j a v a 2 s . co m*/ return (getStringValue() == null) ? context.getString(R.string.label_not_set) : DateTime.parse(getStringValue(), ISODateTimeFormat.dateTimeNoMillis()) .toString(NeoTree.NeoTreeFormat.DATE); case SET_ID: case ID: //return String.format("%s - %s", getStringValue(), getValueLabel()); return getValueLabel(); case NUMBER: final int decimalDigits = (TextUtils.isEmpty(getFormat())) ? 0 : getFormat().length(); return (getDoubleValue() == null) ? context.getString(R.string.label_not_set) : String.format("%." + decimalDigits + "f", getDoubleValue()); case PERIOD: return (getStringValue() == null) ? context.getString(R.string.label_not_set) : Period.parse(getStringValue(), ISOPeriodFormat.standard()) .toString(NeoTree.NeoTreeFormat.PERIOD); case STRING: return (getStringValue() == null) ? context.getString(R.string.label_not_set) : getStringValue(); case TIME: return (getStringValue() == null) ? context.getString(R.string.label_not_set) : DateTime.parse(getStringValue(), ISODateTimeFormat.dateTimeNoMillis()) .toString(NeoTree.NeoTreeFormat.TIME); case VOID: default: break; } return ""; }
From source file:org.neotree.model.realm.SessionValue.java
License:Open Source License
@JsonIgnore @SuppressWarnings("unchecked") public String getValueAsExportString(Context context) { switch (getDataTypeAsObject()) { case BOOLEAN: return (getBooleanValue() != null && getBooleanValue()) ? "Yes" : "No"; case DATETIME: return (getStringValue() == null) ? context.getString(R.string.label_not_set) : DateTime.parse(getStringValue(), ISODateTimeFormat.dateTimeNoMillis()) .toString(NeoTree.NeoTreeFormat.DATETIME_EXPORT); case DATE:/*from www . j a v a 2s. c o m*/ return (getStringValue() == null) ? context.getString(R.string.label_not_set) : DateTime.parse(getStringValue(), ISODateTimeFormat.dateTimeNoMillis()) .toString(NeoTree.NeoTreeFormat.DATE_EXPORT); case ID: case STRING: return getStringValue(); case NUMBER: final int decimalDigits = (TextUtils.isEmpty(getFormat())) ? 0 : getFormat().length(); return (getDoubleValue() == null) ? context.getString(R.string.label_not_set) : String.format("%." + decimalDigits + "f", getDoubleValue()); case PERIOD: return (getStringValue() == null) ? context.getString(R.string.label_not_set) : Period.parse(getStringValue(), ISOPeriodFormat.standard()) .toString(NeoTree.NeoTreeFormat.PERIOD); case TIME: return (getStringValue() == null) ? context.getString(R.string.label_not_set) : DateTime.parse(getStringValue(), ISODateTimeFormat.dateTimeNoMillis()) .toString(NeoTree.NeoTreeFormat.TIME); case SET_ID: case VOID: default: break; } return null; }
From source file:org.supercsv.cellprocessor.joda.ParsePeriod.java
License:Apache License
/** * {@inheritDoc}//w ww . j a v a 2 s . c o m * * @throws SuperCsvCellProcessorException * if value is null or is not a String */ public Object execute(final Object value, final CsvContext context) { validateInputNotNull(value, context); if (!(value instanceof String)) { throw new SuperCsvCellProcessorException(String.class, value, context, this); } final String string = (String) value; final Period result; try { if (formatter != null) { result = Period.parse(string, formatter); } else { result = Period.parse(string); } } catch (IllegalArgumentException e) { throw new SuperCsvCellProcessorException("Failed to parse value as a Period", context, this, e); } return next.execute(result, context); }