1 package org.djunits.unit;
2
3 import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
4 import static org.djunits.unit.unitsystem.UnitSystem.SI_ACCEPTED;
5 import static org.djunits.unit.unitsystem.UnitSystem.SI_BASE;
6
7 import org.djunits.unit.unitsystem.UnitSystem;
8
9 /**
10 * Standard time units.
11 * <p>
12 * Copyright (c) 2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13 * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
14 * <p>
15 * $LastChangedDate: 2015-10-04 20:48:33 +0200 (Sun, 04 Oct 2015) $, @version $Revision: 87 $, by $Author: averbraeck $, initial
16 * version May 15, 2014 <br>
17 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18 */
19 public class TimeUnit extends Unit<TimeUnit>
20 {
21 /** */
22 private static final long serialVersionUID = 20140607L;
23
24 /** The SI unit for time is second. */
25 public static final TimeUnit SI;
26
27 /** second. */
28 public static final TimeUnit SECOND;
29
30 /** millisecond. */
31 public static final TimeUnit MILLISECOND;
32
33 /** minute. */
34 public static final TimeUnit MINUTE;
35
36 /** hour. */
37 public static final TimeUnit HOUR;
38
39 /** day. */
40 public static final TimeUnit DAY;
41
42 /** week. */
43 public static final TimeUnit WEEK;
44
45 static
46 {
47 SI = new TimeUnit("TimeUnit.second", "TimeUnit.s", SI_BASE);
48 SECOND = SI;
49 MILLISECOND = new TimeUnit("TimeUnit.millisecond", "TimeUnit.ms", SI_BASE, SECOND, 0.001, true);
50 MINUTE = new TimeUnit("TimeUnit.minute", "TimeUnit.m", SI_ACCEPTED, SECOND, 60.0, true);
51 HOUR = new TimeUnit("TimeUnit.hour", "TimeUnit.h", SI_ACCEPTED, MINUTE, 60.0, true);
52 DAY = new TimeUnit("TimeUnit.day", "TimeUnit.d", SI_ACCEPTED, HOUR, 24.0, true);
53 WEEK = new TimeUnit("TimeUnit.week", "TimeUnit.w", OTHER, DAY, 7.0, true);
54 }
55
56 /**
57 * Build a standard TimeUnit.
58 * @param nameKey the key to the locale file for the long name of the unit
59 * @param abbreviationKey the key to the locale file for the abbreviation of the unit
60 * @param unitSystem the unit system, e.g. SI or Imperial
61 */
62 private TimeUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
63 {
64 super(nameKey, abbreviationKey, unitSystem, true);
65 }
66
67 /**
68 * Build a TimeUnit with a conversion factor to another TimeUnit.
69 * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
70 * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
71 * otherwise the abbreviation itself
72 * @param unitSystem the unit system, e.g. SI or Imperial
73 * @param referenceUnit the unit to convert to
74 * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
75 * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
76 */
77 private TimeUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
78 final UnitSystem unitSystem, final TimeUnit referenceUnit, final double conversionFactorToReferenceUnit,
79 final boolean standardUnit)
80 {
81 super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit,
82 standardUnit);
83 }
84
85 /**
86 * Build a user-defined TimeUnit with a conversion factor to another TimeUnit.
87 * @param name the long name of the unit
88 * @param abbreviation the abbreviation of the unit
89 * @param unitSystem the unit system, e.g. SI or Imperial
90 * @param referenceUnit the unit to convert to
91 * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
92 */
93 public TimeUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
94 final TimeUnit referenceUnit, final double conversionFactorToReferenceUnit)
95 {
96 this(name, abbreviation, unitSystem, referenceUnit, conversionFactorToReferenceUnit, false);
97 }
98
99 /** {@inheritDoc} */
100 @Override
101 public final TimeUnit getStandardUnit()
102 {
103 return SECOND;
104 }
105
106 /** {@inheritDoc} */
107 @Override
108 public final String getSICoefficientsString()
109 {
110 return "s";
111 }
112
113 }