static protected Unit makeUnit(String name) throws UnitException { UnitFormat format = UnitFormatManager.instance(); return format.parse(name); }
public static void main(final String[] args) throws Exception { final UnitFormat format = UnitFormatManager.instance(); Unit t1 = format.parse("secs since 1970-01-01 00:00:00"); final Unit t2 = format.parse("secs since 1999-02-03 00:00:00"); System.out.println("t1 = " + t1); System.out.println("t2 = " + t2); System.out.println("t1.isCompatible(t2) = " + t1.isCompatible(t2)); System.out.println("t2.convertTo(0.0, t1) = " + t2.convertTo(0.0, t1)); t1 = format.parse("years since 1930-07-27"); t1 = format.parse("years since 1930"); t1 = format.parse("12 secs since 1970-01-02T00:00:00Z"); System.out.println("format.parse(\"\") = \"" + format.parse("") + '"'); System.out .println("format.parse(\"s\") = \"" + format.parse("s") + '"'); System.out.println("format.parse(\"SeCoNd\") = \"" + format.parse("SeCoNd") + '"'); System.out.println("format.parse(\"min\") = \"" + format.parse("min") + '"'); System.out.println("format.parse(\"min\").toString() = \"" + format.parse("min").toString() + '"'); System.out.println("format.parse(\"60 s\") = \"" + format.parse("60 s") + '"'); System.out.println("format.parse(\"Cel\") = \"" + format.parse("Cel") + '"'); System.out.println("format.parse(\"Cel\").toString() = \"" + format.parse("Cel").toString() + '"'); System.out .println("format.parse(\"min @ 1970-01-01 00:00:00 UTC\") = \"" + format.parse("min @ 1970-01-01 00:00:00 UTC") + '"'); System.out
public void testBasic() throws UnitException { UnitFormat format = UnitFormatManager.instance(); Unit meter = format.parse("meter"); Unit second = format.parse("second"); Unit meterPerSecondUnit = meter.divideBy(second); Unit knot = format.parse("knot"); assert (meterPerSecondUnit.isCompatible(knot)); logger.debug("5 knots is {} {}", knot.convertTo(5, meterPerSecondUnit), format.format(meterPerSecondUnit)); Assert2.assertNearlyEquals(2.5722222f, knot.convertTo(5, meterPerSecondUnit)); }
public static void main(final String[] args) throws Exception { final UnitFormat format = UnitFormatManager.instance(); Unit t1 = format.parse("secs since 1970-01-01 00:00:00"); final Unit t2 = format.parse("secs since 1999-02-03 00:00:00"); System.out.println("t1 = " + t1); System.out.println("t2 = " + t2); System.out.println("t1.isCompatible(t2) = " + t1.isCompatible(t2)); System.out.println("t2.convertTo(0.0, t1) = " + t2.convertTo(0.0, t1)); t1 = format.parse("years since 1930-07-27"); t1 = format.parse("years since 1930"); t1 = format.parse("12 secs since 1970-01-02T00:00:00Z"); System.out.println("format.parse(\"\") = \"" + format.parse("") + '"'); System.out .println("format.parse(\"s\") = \"" + format.parse("s") + '"'); System.out.println("format.parse(\"SeCoNd\") = \"" + format.parse("SeCoNd") + '"'); System.out.println("format.parse(\"min\") = \"" + format.parse("min") + '"'); System.out.println("format.parse(\"min\").toString() = \"" + format.parse("min").toString() + '"'); System.out.println("format.parse(\"60 s\") = \"" + format.parse("60 s") + '"'); System.out.println("format.parse(\"Cel\") = \"" + format.parse("Cel") + '"'); System.out.println("format.parse(\"Cel\").toString() = \"" + format.parse("Cel").toString() + '"'); System.out .println("format.parse(\"min @ 1970-01-01 00:00:00 UTC\") = \"" + format.parse("min @ 1970-01-01 00:00:00 UTC") + '"'); System.out
static protected Unit makeUnit(String name) throws Exception { UnitFormat format = UnitFormatManager.instance(); return format.parse(name); }
static protected Unit makeUnit(String name) throws Exception { UnitFormat format = UnitFormatManager.instance(); return format.parse(name); }
/** * Return true if unitString1 is convertible to unitString2 * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible * @throws Exception if units parsing fails */ static public boolean isCompatibleWithExceptions(String unitString1, String unitString2) throws Exception { UnitFormat format = UnitFormatManager.instance(); Unit uu1 = format.parse(unitString1); Unit uu2 = format.parse(unitString2); return uu1.isCompatible(uu2); }
/** * Return true if unitString1 is convertible to unitString2 * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible * @throws UnitException if units parsing fails */ static public boolean isCompatibleWithExceptions(String unitString1, String unitString2) throws UnitException { UnitFormat format = UnitFormatManager.instance(); Unit uu1 = format.parse(unitString1); Unit uu2 = format.parse(unitString2); return uu1.isCompatible(uu2); }
/** * Return true if unitString1 is convertible to unitString2 * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible * @throws Exception if units parsing fails */ static public boolean isCompatibleWithExceptions(String unitString1, String unitString2) throws Exception { UnitFormat format = UnitFormatManager.instance(); Unit uu1 = format.parse(unitString1); Unit uu2 = format.parse(unitString2); return uu1.isCompatible(uu2); }
public static void main(String[] args) throws Exception { UnitFormat udunit = UnitFormatManager.instance(); //String text = "days since 2009-06-14 04:00:00"; String text2 = "days since 2009-06-14 04:00:00 +00:00"; Unit uu2 = udunit.parse(text2); System.out.printf("%s == %s %n", text2, uu2); String text = "days since 2009-06-14 04:00:00"; Unit uu = udunit.parse(text); System.out.printf("%s == %s %n", text, uu); Unit ref = udunit.parse("ms since 1970-01-01"); Converter converter = uu.getConverterTo(ref); DateFormatter formatter = new DateFormatter(); double val = converter.convert(1.0); Date d = new Date( (long) val); System.out.printf(" val=%f date=%s (%s)%n", 1.0, d, formatter.toDateTimeStringISO(d)); double val2 = converter.convert(2.0); Date d2 = new Date( (long) val2); System.out.printf(" val=%f date=%s (%s)%n", 2.0, d, formatter.toDateTimeStringISO(d2)); }
/** * Return true if unitString1 is compatible to unitString2, * meaning one can be converted to the other. * If either unit string is illegal, return false. * @param unitString check if this is compatible with unitString * @return true if compatible */ public boolean isCompatible(String unitString) { Unit uuWant; try { UnitFormat format = UnitFormatManager.instance(); uuWant = format.parse(unitString); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString + " got Exception1 " + e); return false; } return uu.isCompatible(uuWant); }
/** * Return true if unitString1 is compatible to unitString2, * meaning one can be converted to the other. * If either unit string is illegal, return false. * @param unitString check if this is compatible with unitString * @return true if compatible */ public boolean isCompatible(String unitString) { Unit uuWant; try { UnitFormat format = UnitFormatManager.instance(); uuWant = format.parse(unitString); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString + " got Exception1 " + e); return false; } return uu.isCompatible(uuWant); }
/** * Return true if unitString1 is compatible to unitString2, * meaning one can be converted to the other. * If either unit string is illegal, return false. * @param unitString check if this is compatible with unitString * @return true if compatible */ public boolean isCompatible(String unitString) { Unit uuWant; try { UnitFormat format = UnitFormatManager.instance(); uuWant = format.parse(unitString); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString + " got Exception1 " + e); return false; } return uu.isCompatible(uuWant); }
public static void main(String[] args) throws Exception { UnitFormat udunit = UnitFormatManager.instance(); //String text = "days since 2009-06-14 04:00:00"; String text2 = "days since 2009-06-14 04:00:00 +00:00"; Unit uu2 = udunit.parse(text2); System.out.printf("%s == %s %n", text2, uu2); String text = "days since 2009-06-14 04:00:00"; Unit uu = udunit.parse(text); System.out.printf("%s == %s %n", text, uu); Unit ref = udunit.parse("ms since 1970-01-01"); Converter converter = uu.getConverterTo(ref); DateFormatter formatter = new DateFormatter(); double val = converter.convert(1.0); Date d = new Date( (long) val); System.out.printf(" val=%f date=%s (%s)%n", 1.0, d, formatter.toDateTimeStringISO(d)); double val2 = converter.convert(2.0); Date d2 = new Date( (long) val2); System.out.printf(" val=%f date=%s (%s)%n", 2.0, d, formatter.toDateTimeStringISO(d2)); }
public static void main(String[] args) throws Exception { UnitFormat udunit = UnitFormatManager.instance(); //String text = "days since 2009-06-14 04:00:00"; String text2 = "days since 2009-06-14 04:00:00 +00:00"; Unit uu2 = udunit.parse(text2); System.out.printf("%s == %s %n", text2, uu2); String text = "days since 2009-06-14 04:00:00"; Unit uu = udunit.parse(text); System.out.printf("%s == %s %n", text, uu); Unit ref = udunit.parse("ms since 1970-01-01"); Converter converter = uu.getConverterTo(ref); DateFormatter formatter = new DateFormatter(); double val = converter.convert(1.0); Date d = new Date((long) val); System.out.printf(" val=%f date=%s (%s)%n", 1.0, d, formatter.toDateTimeStringISO(d)); double val2 = converter.convert(2.0); Date d2 = new Date((long) val2); System.out.printf(" val=%f date=%s (%s)%n", 2.0, d, formatter.toDateTimeStringISO(d2)); }
/** * Return true if unitString1 is compatible to unitString2, meaning one can be converted to the other. * If either unit string is illegal, return false. * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible */ static public boolean isCompatible(String unitString1, String unitString2) { Unit uu1, uu2; try { UnitFormat format = UnitFormatManager.instance(); uu1 = format.parse(unitString1); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString1 + " got Exception1 " + e); return false; } try { UnitFormat format = UnitFormatManager.instance(); uu2 = format.parse(unitString2); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString2 + " got Exception2 " + e); return false; } //System.out.println("udunits isCompatible "+ uu1+ " "+ uu2); return uu1.isCompatible(uu2); }
/** * Return true if unitString1 is compatible to unitString2, meaning one can be converted to the other. * If either unit string is illegal, return false. * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible */ static public boolean isCompatible(String unitString1, String unitString2) { Unit uu1, uu2; try { UnitFormat format = UnitFormatManager.instance(); uu1 = format.parse(unitString1); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString1 + " got Exception1 " + e); return false; } try { UnitFormat format = UnitFormatManager.instance(); uu2 = format.parse(unitString2); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString2 + " got Exception2 " + e); return false; } //System.out.println("udunits isCompatible "+ uu1+ " "+ uu2); return uu1.isCompatible(uu2); }
/** * Return true if unitString1 is compatible to unitString2, meaning one can be converted to the other. * If either unit string is illegal, return false. * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible */ static public boolean isCompatible(String unitString1, String unitString2) { Unit uu1, uu2; try { UnitFormat format = UnitFormatManager.instance(); uu1 = format.parse(unitString1); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString1 + " got Exception1 " + e); return false; } try { UnitFormat format = UnitFormatManager.instance(); uu2 = format.parse(unitString2); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString2 + " got Exception2 " + e); return false; } //System.out.println("udunits isCompatible "+ uu1+ " "+ uu2); return uu1.isCompatible(uu2); }
public void testException() throws UnitException { UnitFormat format = UnitFormatManager.instance(); Unit uu = format.parse("barf"); logger.debug("Parse ok = {}", uu); } }
private Date getBase(String s) throws Exception { Unit u = format.parse(s); assert u instanceof TimeScaleUnit : s; TimeScaleUnit tu = (TimeScaleUnit) u; return tu.getOrigin(); }