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.ReadWritableInterval; 21 import org.joda.time.ReadWritablePeriod; 22 import org.joda.time.ReadableInterval; 23 24 30 class ReadableIntervalConverter extends AbstractConverter 31 implements IntervalConverter, DurationConverter, PeriodConverter { 32 33 36 static final ReadableIntervalConverter INSTANCE = new ReadableIntervalConverter(); 37 38 41 protected ReadableIntervalConverter() { 42 super(); 43 } 44 45 51 public long getDurationMillis(Object object) { 52 return (((ReadableInterval) object)).toDurationMillis(); 53 } 54 55 63 public void setInto(ReadWritablePeriod writablePeriod, Object object, Chronology chrono) { 64 ReadableInterval interval = (ReadableInterval) object; 65 chrono = (chrono != null ? chrono : DateTimeUtils.getIntervalChronology(interval)); 66 long start = interval.getStartMillis(); 67 long end = interval.getEndMillis(); 68 int[] values = chrono.get(writablePeriod, start, end); 69 for (int i = 0; i < values.length; i++) { 70 writablePeriod.setValue(i, values[i]); 71 } 72 } 73 74 85 public boolean isReadableInterval(Object object, Chronology chrono) { 86 return true; 87 } 88 89 98 public void setInto(ReadWritableInterval writableInterval, Object object, Chronology chrono) { 99 ReadableInterval input = (ReadableInterval) object; 100 writableInterval.setInterval(input); 101 if (chrono != null) { 102 writableInterval.setChronology(chrono); 103 } else { 104 writableInterval.setChronology(input.getChronology()); 105 } 106 } 107 108 112 public Class getSupportedType() { 113 return ReadableInterval.class; 114 } 115 116 } 117 | Popular Tags |