1 9 package org.jscience.physics.quantities; 10 11 import java.util.Date ; 12 13 import org.jscience.physics.units.SI; 14 import org.jscience.physics.units.Unit; 15 16 23 public class Duration extends Quantity { 24 25 28 private final static Unit<Duration> UNIT = SI.SECOND; 29 30 33 private final static Factory<Duration> FACTORY = new Factory<Duration>(UNIT) { 34 protected Duration create() { 35 return new Duration(); 36 } 37 }; 38 39 42 public final static Duration ZERO = Quantity.valueOf(0, UNIT); 43 44 47 protected Duration() { 48 } 49 50 55 public static void showAs(Unit unit) { 56 QuantityFormat.show(Duration.class, unit); 57 } 58 59 63 70 public static Duration between(Date from, Date to) { 71 return Quantity.valueOf(from.getTime() - to.getTime(), 0.5, SI 72 .MILLI(SI.SECOND)); 73 } 74 75 82 public Date addTo(Date date) { 83 return new Date (date.getTime() 84 + this.to(SI.MILLI(SI.SECOND)).longValue()); 85 } 86 87 94 public Date subtractFrom(Date date) { 95 return new Date (date.getTime() 96 - this.to(SI.MILLI(SI.SECOND)).longValue()); 97 } 98 99 private static final long serialVersionUID = 1L; 100 } 101 | Popular Tags |