Java Code Examples for org.joda.time.PeriodType#millis()
The following examples show how to use
org.joda.time.PeriodType#millis() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigUtils.java From incubator-pinot with Apache License 2.0 | 6 votes |
/** * Helper for parsing a period string from config (e.g. '3 days', '1min', '3600000') * * @param period * @return */ public static Period parsePeriod(String period) { Matcher m = PATTERN_PERIOD.matcher(period); if (!m.find()) { throw new IllegalArgumentException(String.format("Could not parse period expression '%s'", period)); } int size = Integer.valueOf(m.group(1).trim()); PeriodType t = PeriodType.millis(); if (m.group(2).length() > 0) { t = parsePeriodType(m.group(2).trim()); } return new Period().withFieldAdded(t.getFieldType(0), size); }
Example 2
Source File: TestReadableIntervalConverter.java From astor with GNU General Public License v2.0 | 5 votes |
public void testSetIntoPeriod_Object1() throws Exception { Interval i = new Interval(100L, 223L); MutablePeriod m = new MutablePeriod(PeriodType.millis()); ReadableIntervalConverter.INSTANCE.setInto(m, i, null); assertEquals(0, m.getYears()); assertEquals(0, m.getMonths()); assertEquals(0, m.getWeeks()); assertEquals(0, m.getDays()); assertEquals(0, m.getHours()); assertEquals(0, m.getMinutes()); assertEquals(0, m.getSeconds()); assertEquals(123, m.getMillis()); }
Example 3
Source File: TestReadableIntervalConverter.java From astor with GNU General Public License v2.0 | 5 votes |
public void testSetIntoPeriod_Object2() throws Exception { Interval i = new Interval(100L, 223L); MutablePeriod m = new MutablePeriod(PeriodType.millis()); ReadableIntervalConverter.INSTANCE.setInto(m, i, CopticChronology.getInstance()); assertEquals(0, m.getYears()); assertEquals(0, m.getMonths()); assertEquals(0, m.getWeeks()); assertEquals(0, m.getDays()); assertEquals(0, m.getHours()); assertEquals(0, m.getMinutes()); assertEquals(0, m.getSeconds()); assertEquals(123, m.getMillis()); }
Example 4
Source File: TestReadableIntervalConverter.java From astor with GNU General Public License v2.0 | 5 votes |
public void testSetIntoPeriod_Object1() throws Exception { Interval i = new Interval(100L, 223L); MutablePeriod m = new MutablePeriod(PeriodType.millis()); ReadableIntervalConverter.INSTANCE.setInto(m, i, null); assertEquals(0, m.getYears()); assertEquals(0, m.getMonths()); assertEquals(0, m.getWeeks()); assertEquals(0, m.getDays()); assertEquals(0, m.getHours()); assertEquals(0, m.getMinutes()); assertEquals(0, m.getSeconds()); assertEquals(123, m.getMillis()); }
Example 5
Source File: TestReadableIntervalConverter.java From astor with GNU General Public License v2.0 | 5 votes |
public void testSetIntoPeriod_Object2() throws Exception { Interval i = new Interval(100L, 223L); MutablePeriod m = new MutablePeriod(PeriodType.millis()); ReadableIntervalConverter.INSTANCE.setInto(m, i, CopticChronology.getInstance()); assertEquals(0, m.getYears()); assertEquals(0, m.getMonths()); assertEquals(0, m.getWeeks()); assertEquals(0, m.getDays()); assertEquals(0, m.getHours()); assertEquals(0, m.getMinutes()); assertEquals(0, m.getSeconds()); assertEquals(123, m.getMillis()); }
Example 6
Source File: ConfigUtils.java From incubator-pinot with Apache License 2.0 | 5 votes |
/** * Helper for heuristically parsing period unit from config (e.g. 'millis', 'hour', 'd') * * @param type period type string * @return PeriodType */ static PeriodType parsePeriodType(String type) { type = type.toLowerCase(); if (type.startsWith("y") || type.startsWith("a")) { return PeriodType.years(); } if (type.startsWith("mo")) { return PeriodType.months(); } if (type.startsWith("w")) { return PeriodType.weeks(); } if (type.startsWith("d")) { return PeriodType.days(); } if (type.startsWith("h")) { return PeriodType.hours(); } if (type.startsWith("s")) { return PeriodType.seconds(); } if (type.startsWith("mill") || type.startsWith("ms")) { return PeriodType.millis(); } if (type.startsWith("m")) { return PeriodType.minutes(); } throw new IllegalArgumentException(String.format("Invalid period type '%s'", type)); }
Example 7
Source File: TestNullConverter.java From astor with GNU General Public License v2.0 | 4 votes |
public void testSetInto_Object() throws Exception { MutablePeriod m = new MutablePeriod(PeriodType.millis()); NullConverter.INSTANCE.setInto(m, null, null); assertEquals(0L, m.getMillis()); }
Example 8
Source File: TestNullConverter.java From astor with GNU General Public License v2.0 | 4 votes |
public void testSetInto_Object() throws Exception { MutablePeriod m = new MutablePeriod(PeriodType.millis()); NullConverter.INSTANCE.setInto(m, null, null); assertEquals(0L, m.getMillis()); }