1 16 package org.joda.time.convert; 17 18 import org.joda.time.Chronology; 19 import org.joda.time.DateTimeUtils; 20 import org.joda.time.ReadWritablePeriod; 21 import org.joda.time.ReadableDuration; 22 23 30 class ReadableDurationConverter extends AbstractConverter 31 implements DurationConverter, PeriodConverter { 32 33 36 static final ReadableDurationConverter INSTANCE = new ReadableDurationConverter(); 37 38 41 protected ReadableDurationConverter() { 42 super(); 43 } 44 45 55 public long getDurationMillis(Object object) { 56 return ((ReadableDuration) object).getMillis(); 57 } 58 59 71 public void setInto(ReadWritablePeriod writablePeriod, Object object, Chronology chrono) { 72 ReadableDuration dur = (ReadableDuration) object; 73 chrono = DateTimeUtils.getChronology(chrono); 74 long duration = dur.getMillis(); 75 int[] values = chrono.get(writablePeriod, duration); 76 for (int i = 0; i < values.length; i++) { 77 writablePeriod.setValue(i, values[i]); 78 } 79 } 80 81 87 public Class getSupportedType() { 88 return ReadableDuration.class; 89 } 90 91 } 92 | Popular Tags |