/** * Clones this unit, changing the identifier. * * @param id The new identifier. * @return This unit with the new identifier. */ public Unit clone(final UnitName id) { Unit clone; try { clone = new TimeScaleUnit(getUnit(), getOrigin(), id); } catch (final UnitException e) { clone = null; // can't happen } return clone; }
public Unit shiftTo(final Date origin) throws ShiftException { return TimeScaleUnit.getInstance(this, origin); }
/** Get the origin Date. * @return Date or null if not a time unit. */ public Date getDateOrigin() { if (!(uu instanceof TimeScaleUnit)) return null; TimeScaleUnit tu = (TimeScaleUnit) uu; return tu.getOrigin(); }
/** * Returns the derived unit underlying the reference time unit. * * @return The derived unit underlying the reference time unit. */ public DerivedUnit getDerivedUnit() { return getUnit().getDerivedUnit(); }
static Unit getInstance(final Unit unit, final Date origin) throws ShiftException { try { return unit instanceof TimeScaleUnit ? new TimeScaleUnit(((TimeScaleUnit) unit)._unit, origin) : new TimeScaleUnit(unit, origin); } catch (final Exception e) { throw (ShiftException) new ShiftException(unit, origin) .initCause(e); } }
/** * Returns the string representation of this unit. * * @return The string representation of this unit. */ @Override public String toString() { final String string = super.toString(); // get symbol or name return string != null ? string : getCanonicalString(); }
/** * Get the origin Date. * * @return Date or null if not a time unit. */ public Date getDateOrigin() { if (!(uu instanceof TimeScaleUnit)) return null; TimeScaleUnit tu = (TimeScaleUnit) uu; return tu.getOrigin(); }
/** * Returns the derived unit underlying the reference time unit. * * @return The derived unit underlying the reference time unit. */ public DerivedUnit getDerivedUnit() { return getUnit().getDerivedUnit(); }
static Unit getInstance(final Unit unit, final Date origin) throws ShiftException { try { return unit instanceof TimeScaleUnit ? new TimeScaleUnit(((TimeScaleUnit) unit)._unit, origin) : new TimeScaleUnit(unit, origin); } catch (final Exception e) { throw (ShiftException) new ShiftException(unit, origin) .initCause(e); } }
/** * Returns the string representation of this unit. * * @return The string representation of this unit. */ @Override public String toString() { final String string = super.toString(); // get symbol or name return string != null ? string : getCanonicalString(); }
/** * Clones this unit, changing the identifier. * * @param id The new identifier. * @return This unit with the new identifier. */ public Unit clone(final UnitName id) { Unit clone; try { clone = new TimeScaleUnit(getUnit(), getOrigin(), id); } catch (final UnitException e) { clone = null; // can't happen } return clone; }
/** Get the origin Date. * @return Date or null if not a time unit. */ public Date getDateOrigin() { if (!(uu instanceof TimeScaleUnit)) return null; TimeScaleUnit tu = (TimeScaleUnit) uu; return tu.getOrigin(); }
@Override public Unit shiftTo(final double origin) throws ShiftException { Date newOrigin; try { newOrigin = new Date(_origin.getTime() + (long) (_unit.convertTo(origin, SECOND) * 1000)); } catch (final ConversionException e) { throw (ShiftException) new ShiftException(this, origin) .initCause(e); } try { return new TimeScaleUnit(_unit, newOrigin); } catch (final BadUnitException e) { throw new AssertionError(); } catch (final UnitSystemException e) { throw (ShiftException) new ShiftException(this, origin) .initCause(e); } }
@Override public Unit shiftTo(final Date origin) throws ShiftException { return getInstance(_unit, origin); }
protected MyConverter(final TimeScaleUnit fromUnit, final Unit toUnit) throws ConversionException { super(fromUnit, toUnit); converter = fromUnit.getUnit().getConverterTo( ((TimeScaleUnit) toUnit).getUnit()); offset = SI.SECOND.convertTo( (fromUnit.getOrigin().getTime() - ((TimeScaleUnit) toUnit) .getOrigin().getTime()) / 1000.0, ((TimeScaleUnit) toUnit).getUnit()); }
private Date getBase(String s) throws Exception { Unit u = format.parse(s); assert u instanceof TimeScaleUnit : s; TimeScaleUnit tu = (TimeScaleUnit) u; return tu.getOrigin(); }
@Override public Unit shiftTo(final double origin) throws ShiftException { Date newOrigin; try { newOrigin = new Date(_origin.getTime() + (long) (_unit.convertTo(origin, SECOND) * 1000)); } catch (final ConversionException e) { throw (ShiftException) new ShiftException(this, origin) .initCause(e); } try { return new TimeScaleUnit(_unit, newOrigin); } catch (final BadUnitException e) { throw new AssertionError(); } catch (final UnitSystemException e) { throw (ShiftException) new ShiftException(this, origin) .initCause(e); } }