• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GENERATED SOURCE. DO NOT MODIFY. */
2 // © 2016 and later: Unicode, Inc. and others.
3 // License & terms of use: http://www.unicode.org/copyright.html#License
4 /*
5 ******************************************************************************
6 * Copyright (C) 2007, International Business Machines Corporation and   *
7 * others. All Rights Reserved.                                               *
8 ******************************************************************************
9 */
10 
11 package ohos.global.icu.impl.duration;
12 
13 /**
14  * 'Enum' for individual time units.  Not an actual enum so that it can be
15  * used by Java 1.4.
16  * @hide exposed on OHOS
17  */
18 public final class TimeUnit {
19   /** The name of this unit, a key, not for localization. */
20   final String name;
21 
22   /** The ordinal of the unit, in order from largest to smallest. */
23   final byte ordinal;
24 
25   /** Private constructor */
TimeUnit(String name, int ordinal)26   private TimeUnit(String name, int ordinal) {
27     this.name = name;
28     this.ordinal = (byte) ordinal;
29   }
30 
31   @Override
toString()32   public String toString() {
33     return name;
34   }
35 
36   /** Represents a year. */
37   public static final TimeUnit YEAR = new TimeUnit("year", 0);
38 
39   /** Represents a month. */
40   public static final TimeUnit MONTH = new TimeUnit("month", 1);
41 
42   /** Represents a week. */
43   public static final TimeUnit WEEK = new TimeUnit("week", 2);
44 
45   /** Represents a day. */
46   public static final TimeUnit DAY = new TimeUnit("day", 3);
47 
48   /** Represents an hour. */
49   public static final TimeUnit HOUR = new TimeUnit("hour", 4);
50 
51   /** Represents a minute. */
52   public static final TimeUnit MINUTE = new TimeUnit("minute", 5);
53 
54   /** Represents a second. */
55   public static final TimeUnit SECOND = new TimeUnit("second", 6);
56 
57   /** Represents a millisecond. */
58   public static final TimeUnit MILLISECOND = new TimeUnit("millisecond", 7);
59 
60   /** Returns the next larger time unit, or null if this is the largest. */
larger()61   public TimeUnit larger() {
62     return ordinal == 0 ? null : units[ordinal - 1];
63   }
64 
65   /** Returns the next smaller time unit, or null if this is the smallest. */
smaller()66   public TimeUnit smaller() {
67     return ordinal == units.length - 1 ? null : units[ordinal + 1];
68   }
69 
70   /** The list of units, in order from largest to smallest. */
71   static final TimeUnit[] units = {
72     YEAR, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND, MILLISECOND
73   };
74 
75     /** Returns the ordinal value of this time unit, largest is 0. **/
ordinal()76   public int ordinal() {
77     return ordinal;
78   }
79 
80   /** Approximate, durations for the units independent of the time at which
81       they are measured */
82 
83   // hack, initialization long array using expressions with 'L' at end doesn't
84   // compute entire expression using 'long'.  differs from initializtion of
85   // a single constant
86   static final long[] approxDurations = {
87     36525L*24*60*60*10, 3045*24*60*60*10L, 7*24*60*60*1000L, 24*60*60*1000L,
88     60*60*1000L, 60*1000L, 1000L, 1L
89   };
90 }
91