]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/classes/core/src/com/ibm/icu/util/UniversalTimeScale.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / classes / core / src / com / ibm / icu / util / UniversalTimeScale.java
1 /*\r
2  *********************************************************************************\r
3  * Copyright (C) 2004-2010, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                  *\r
5  *********************************************************************************\r
6  *\r
7  */\r
8 \r
9 package com.ibm.icu.util;\r
10 \r
11 import com.ibm.icu.math.BigDecimal;\r
12 \r
13 /** \r
14  * There are quite a few different conventions for binary datetime, depending on different\r
15  * platforms and protocols. Some of these have severe drawbacks. For example, people using\r
16  * Unix time (seconds since Jan 1, 1970, usually in a 32-bit integer)\r
17  * think that they are safe until near the year 2038.\r
18  * But cases can and do arise where arithmetic manipulations causes serious problems. Consider\r
19  * the computation of the average of two datetimes, for example: if one calculates them with\r
20  * <code>averageTime = (time1 + time2)/2</code>, there will be overflow even with dates\r
21  * beginning in 2004. Moreover, even if these problems don't occur, there is the issue of\r
22  * conversion back and forth between different systems.\r
23  *\r
24  * <p>Binary datetimes differ in a number of ways: the datatype, the unit,\r
25  * and the epoch (origin). We refer to these as time scales.</p>\r
26  *\r
27  * <p>ICU implements a universal time scale that is similar to the\r
28  * .NET framework's System.DateTime. The universal time scale is a\r
29  * 64-bit integer that holds ticks since midnight, January 1st, 0001.\r
30  * (One tick is 100 nanoseconds.)\r
31  * Negative values are supported. This has enough range to guarantee that\r
32  * calculations involving dates around the present are safe.</p>\r
33  *\r
34  * <p>The universal time scale always measures time according to the\r
35  * proleptic Gregorian calendar. That is, the Gregorian calendar's\r
36  * leap year rules are used for all times, even before 1582 when it was\r
37  * introduced. (This is different from the default ICU calendar which\r
38  * switches from the Julian to the Gregorian calendar in 1582.\r
39  * See GregorianCalendar.setGregorianChange() and ucal_setGregorianChange().)</p>\r
40  *\r
41  * ICU provides conversion functions to and from all other major time\r
42  * scales, allowing datetimes in any time scale to be converted to the\r
43  * universal time scale, safely manipulated, and converted back to any other\r
44  * datetime time scale.</p>\r
45  *\r
46  * <p>For more details and background, see the\r
47  * <a href="http://www.icu-project.org/userguide/universalTimeScale.html">Universal Time Scale</a>\r
48  * chapter in the ICU User Guide.</p>\r
49  *\r
50  * @stable ICU 3.2\r
51  */\r
52 \r
53 public final class UniversalTimeScale\r
54 {\r
55     /**\r
56      * Used in the JDK. Data is a <code>long</code>. Value\r
57      * is milliseconds since January 1, 1970.\r
58      *\r
59      * @stable ICU 3.2\r
60      */\r
61     public static final int JAVA_TIME = 0;\r
62 \r
63     /**\r
64      * Used in Unix systems. Data is an <code>int</code> or a <code>long</code>. Value\r
65      * is seconds since January 1, 1970.\r
66      *\r
67      * @stable ICU 3.2\r
68      */\r
69     public static final int UNIX_TIME = 1;\r
70 \r
71     /**\r
72      * Used in the ICU4C. Data is a <code>double</code>. Value\r
73      * is milliseconds since January 1, 1970.\r
74      *\r
75      * @stable ICU 3.2\r
76      */\r
77     public static final int ICU4C_TIME = 2;\r
78 \r
79     /**\r
80      * Used in Windows for file times. Data is a <code>long</code>. Value\r
81      * is ticks (1 tick == 100 nanoseconds) since January 1, 1601.\r
82      *\r
83      * @stable ICU 3.2\r
84      */\r
85     public static final int WINDOWS_FILE_TIME = 3;\r
86 \r
87     /**\r
88      * Used in the .NET framework's <code>System.DateTime</code> structure.\r
89      * Data is a <code>long</code>. Value is ticks (1 tick == 100 nanoseconds) since January 1, 0001.\r
90      *\r
91      * @stable ICU 3.2\r
92      */\r
93     public static final int DOTNET_DATE_TIME = 4;\r
94 \r
95     /**\r
96      * Used in older Macintosh systems. Data is an <code>int</code>. Value\r
97      * is seconds since January 1, 1904.\r
98      *\r
99      * @stable ICU 3.2\r
100      */\r
101     public static final int MAC_OLD_TIME = 5;\r
102 \r
103     /**\r
104      * Used in the JDK. Data is a <code>double</code>. Value\r
105      * is milliseconds since January 1, 2001.\r
106      *\r
107      * @stable ICU 3.2\r
108      */\r
109     public static final int MAC_TIME = 6;\r
110 \r
111     /**\r
112      * Used in Excel. Data is a <code>?unknown?</code>. Value\r
113      * is days since December 31, 1899.\r
114      *\r
115      * @stable ICU 3.2\r
116      */\r
117     public static final int EXCEL_TIME = 7;\r
118 \r
119     /**\r
120      * Used in DB2. Data is a <code>?unknown?</code>. Value\r
121      * is days since December 31, 1899.\r
122      *\r
123      * @stable ICU 3.2\r
124      */\r
125     public static final int DB2_TIME = 8;\r
126 \r
127     /**\r
128      * Data is a <code>long</code>. Value is microseconds since January 1, 1970.\r
129      * Similar to Unix time (linear value from 1970) and struct timeval\r
130      * (microseconds resolution).\r
131      *\r
132      * @stable ICU 3.8\r
133      */\r
134     public static final int UNIX_MICROSECONDS_TIME = 9;\r
135     \r
136     /**\r
137      * This is the first unused time scale value.\r
138      *\r
139      * @stable ICU 3.2\r
140      */\r
141     public static final int MAX_SCALE = 10;\r
142     \r
143     /**\r
144      * The constant used to select the units value\r
145      * for a time scale.\r
146      * \r
147      *\r
148      * @stable ICU 3.2\r
149      */\r
150     public static final int UNITS_VALUE = 0;\r
151     \r
152     /**\r
153      * The constant used to select the epoch offset value\r
154      * for a time scale.\r
155      * \r
156      * @see #getTimeScaleValue\r
157      *\r
158      * @stable ICU 3.2\r
159      */\r
160     public static final int EPOCH_OFFSET_VALUE = 1;\r
161     \r
162     /**\r
163      * The constant used to select the minimum from value\r
164      * for a time scale.\r
165      * \r
166      * @see #getTimeScaleValue\r
167      *\r
168      * @stable ICU 3.2\r
169      */\r
170     public static final int FROM_MIN_VALUE = 2;\r
171     \r
172     /**\r
173      * The constant used to select the maximum from value\r
174      * for a time scale.\r
175      * \r
176      * @see #getTimeScaleValue\r
177      *\r
178      * @stable ICU 3.2\r
179      */\r
180     public static final int FROM_MAX_VALUE = 3;\r
181     \r
182     /**\r
183      * The constant used to select the minimum to value\r
184      * for a time scale.\r
185      * \r
186      * @see #getTimeScaleValue\r
187      *\r
188      * @stable ICU 3.2\r
189      */\r
190     public static final int TO_MIN_VALUE = 4;\r
191     \r
192     /**\r
193      * The constant used to select the maximum to value\r
194      * for a time scale.\r
195      * \r
196      * @see #getTimeScaleValue\r
197      *\r
198      * @stable ICU 3.2\r
199      */\r
200     public static final int TO_MAX_VALUE = 5;\r
201     \r
202     /**\r
203      * The constant used to select the epoch plus one value\r
204      * for a time scale.\r
205      * \r
206      * NOTE: This is an internal value. DO NOT USE IT. May not\r
207      * actually be equal to the epoch offset value plus one.\r
208      * \r
209      * @see #getTimeScaleValue\r
210      *\r
211      * @stable ICU 3.2\r
212      */\r
213     public static final int EPOCH_OFFSET_PLUS_1_VALUE = 6;\r
214     \r
215     /**\r
216      * The constant used to select the epoch offset minus one value\r
217      * for a time scale.\r
218      * \r
219      * NOTE: This is an internal value. DO NOT USE IT. May not\r
220      * actually be equal to the epoch offset value minus one.\r
221      * \r
222      * @see #getTimeScaleValue\r
223      *\r
224      * @internal\r
225      * @deprecated This API is ICU internal only.\r
226      */\r
227     public static final int EPOCH_OFFSET_MINUS_1_VALUE = 7;\r
228     \r
229     /**\r
230      * The constant used to select the units round value\r
231      * for a time scale.\r
232      * \r
233      * NOTE: This is an internal value. DO NOT USE IT.\r
234      * \r
235      * @see #getTimeScaleValue\r
236      *\r
237      * @internal\r
238      * @deprecated This API is ICU internal only.\r
239      */\r
240     public static final int UNITS_ROUND_VALUE = 8;\r
241     \r
242     /**\r
243      * The constant used to select the minimum safe rounding value\r
244      * for a time scale.\r
245      * \r
246      * NOTE: This is an internal value. DO NOT USE IT.\r
247      * \r
248      * @see #getTimeScaleValue\r
249      *\r
250      * @internal\r
251      * @deprecated This API is ICU internal only.\r
252      */\r
253     public static final int MIN_ROUND_VALUE = 9;\r
254     \r
255     /**\r
256      * The constant used to select the maximum safe rounding value\r
257      * for a time scale.\r
258      * \r
259      * NOTE: This is an internal value. DO NOT USE IT.\r
260      * \r
261      * @see #getTimeScaleValue\r
262      *\r
263      * @internal\r
264      * @deprecated This API is ICU internal only.\r
265      */\r
266     public static final int MAX_ROUND_VALUE = 10;\r
267     \r
268     /**\r
269      * The number of time scale values.\r
270      * \r
271      * NOTE: This is an internal value. DO NOT USE IT.\r
272      * \r
273      * @see #getTimeScaleValue\r
274      *\r
275      * @internal\r
276      * @deprecated This API is ICU internal only.\r
277      */\r
278     public static final int MAX_SCALE_VALUE = 11;\r
279     \r
280     private static final long ticks        = 1;\r
281     private static final long microseconds = ticks * 10;\r
282     private static final long milliseconds = microseconds * 1000;\r
283     private static final long seconds      = milliseconds * 1000;\r
284     private static final long minutes      = seconds * 60;\r
285     private static final long hours        = minutes * 60;\r
286     private static final long days         = hours * 24;\r
287     \r
288     /**\r
289      * This class holds the data that describes a particular\r
290      * time scale.\r
291      */\r
292     private static final class TimeScaleData\r
293     {\r
294         TimeScaleData(long theUnits, long theEpochOffset,\r
295                        long theToMin, long theToMax,\r
296                        long theFromMin, long theFromMax)\r
297         {\r
298             units      = theUnits;\r
299             unitsRound = theUnits / 2;\r
300             \r
301             minRound = Long.MIN_VALUE + unitsRound;\r
302             maxRound = Long.MAX_VALUE - unitsRound;\r
303                         \r
304             epochOffset   = theEpochOffset / theUnits;\r
305             \r
306             if (theUnits == 1) {\r
307                 epochOffsetP1 = epochOffsetM1 = epochOffset;\r
308             } else {\r
309                 epochOffsetP1 = epochOffset + 1;\r
310                 epochOffsetM1 = epochOffset - 1;\r
311             }\r
312             \r
313             toMin = theToMin;\r
314             toMax = theToMax;\r
315             \r
316             fromMin = theFromMin;\r
317             fromMax = theFromMax;\r
318         }\r
319         \r
320         long units;\r
321         long epochOffset;\r
322         long fromMin;\r
323         long fromMax;\r
324         long toMin;\r
325         long toMax;\r
326         \r
327         long epochOffsetP1;\r
328         long epochOffsetM1;\r
329         long unitsRound;\r
330         long minRound;\r
331         long maxRound;\r
332     }\r
333     \r
334     private static final TimeScaleData[] timeScaleTable = {\r
335         new TimeScaleData(milliseconds, 621355968000000000L, -9223372036854774999L, 9223372036854774999L, -984472800485477L,         860201606885477L), // JAVA_TIME\r
336         new TimeScaleData(seconds,      621355968000000000L, -9223372036854775808L, 9223372036854775807L, -984472800485L,               860201606885L), // UNIX_TIME\r
337         new TimeScaleData(milliseconds, 621355968000000000L, -9223372036854774999L, 9223372036854774999L, -984472800485477L,         860201606885477L), // ICU4C_TIME\r
338         new TimeScaleData(ticks,        504911232000000000L, -8718460804854775808L, 9223372036854775807L, -9223372036854775808L, 8718460804854775807L), // WINDOWS_FILE_TIME\r
339         new TimeScaleData(ticks,        000000000000000000L, -9223372036854775808L, 9223372036854775807L, -9223372036854775808L, 9223372036854775807L), // DOTNET_DATE_TIME\r
340         new TimeScaleData(seconds,      600527520000000000L, -9223372036854775808L, 9223372036854775807L, -982389955685L,               862284451685L), // MAC_OLD_TIME\r
341         new TimeScaleData(seconds,      631139040000000000L, -9223372036854775808L, 9223372036854775807L, -985451107685L,               859223299685L), // MAC_TIME\r
342         new TimeScaleData(days,         599265216000000000L, -9223372036854775808L, 9223372036854775807L, -11368793L,                        9981605L), // EXCEL_TIME\r
343         new TimeScaleData(days,         599265216000000000L, -9223372036854775808L, 9223372036854775807L, -11368793L,                        9981605L), // DB2_TIME\r
344         new TimeScaleData(microseconds, 621355968000000000L, -9223372036854775804L, 9223372036854775804L, -984472800485477580L,   860201606885477580L)  // UNIX_MICROSECONDS_TIME\r
345     };\r
346     \r
347     \r
348     /*\r
349      * Prevent construction of this class.\r
350      */\r
351     ///CLOVER:OFF\r
352     private UniversalTimeScale()\r
353     {\r
354         // nothing to do\r
355     }\r
356     ///CLOVER:ON\r
357     \r
358     /**\r
359      * Convert a <code>long</code> datetime from the given time scale to the universal time scale.\r
360      *\r
361      * @param otherTime The <code>long</code> datetime\r
362      * @param timeScale The time scale to convert from\r
363      * \r
364      * @return The datetime converted to the universal time scale\r
365      *\r
366      * @stable ICU 3.2\r
367      */\r
368     public static long from(long otherTime, int timeScale)\r
369     {\r
370         TimeScaleData data = fromRangeCheck(otherTime, timeScale);\r
371                 \r
372         return (otherTime + data.epochOffset) * data.units;\r
373     }\r
374 \r
375     /**\r
376      * Convert a <code>double</code> datetime from the given time scale to the universal time scale.\r
377      * All calculations are done using <code>BigDecimal</code> to guarantee that the value\r
378      * does not go out of range.\r
379      *\r
380      * @param otherTime The <code>double</code> datetime\r
381      * @param timeScale The time scale to convert from\r
382      * \r
383      * @return The datetime converted to the universal time scale\r
384      *\r
385      * @stable ICU 3.2\r
386      */\r
387     public static BigDecimal bigDecimalFrom(double otherTime, int timeScale)\r
388     {\r
389         TimeScaleData data     = getTimeScaleData(timeScale);\r
390         BigDecimal other       = new BigDecimal(String.valueOf(otherTime));\r
391         BigDecimal units       = new BigDecimal(data.units);\r
392         BigDecimal epochOffset = new BigDecimal(data.epochOffset);\r
393         \r
394         return other.add(epochOffset).multiply(units);\r
395     }\r
396 \r
397     /**\r
398      * Convert a <code>long</code> datetime from the given time scale to the universal time scale.\r
399      * All calculations are done using <code>BigDecimal</code> to guarantee that the value\r
400      * does not go out of range.\r
401      *\r
402      * @param otherTime The <code>long</code> datetime\r
403      * @param timeScale The time scale to convert from\r
404      * \r
405      * @return The datetime converted to the universal time scale\r
406      *\r
407      * @stable ICU 3.2\r
408      */\r
409     public static BigDecimal bigDecimalFrom(long otherTime, int timeScale)\r
410     {\r
411         TimeScaleData data     = getTimeScaleData(timeScale);\r
412         BigDecimal other       = new BigDecimal(otherTime);\r
413         BigDecimal units       = new BigDecimal(data.units);\r
414         BigDecimal epochOffset = new BigDecimal(data.epochOffset);\r
415         \r
416         return other.add(epochOffset).multiply(units);\r
417     }\r
418 \r
419     /**\r
420      * Convert a <code>BigDecimal</code> datetime from the given time scale to the universal time scale.\r
421      * All calculations are done using <code>BigDecimal</code> to guarantee that the value\r
422      * does not go out of range.\r
423      *\r
424      * @param otherTime The <code>BigDecimal</code> datetime\r
425      * @param timeScale The time scale to convert from\r
426      * \r
427      * @return The datetime converted to the universal time scale\r
428      *\r
429      * @stable ICU 3.2\r
430      */\r
431     public static BigDecimal bigDecimalFrom(BigDecimal otherTime, int timeScale)\r
432     {\r
433         TimeScaleData data = getTimeScaleData(timeScale);\r
434         \r
435         BigDecimal units = new BigDecimal(data.units);\r
436         BigDecimal epochOffset = new BigDecimal(data.epochOffset);\r
437         \r
438         return otherTime.add(epochOffset).multiply(units);\r
439     }\r
440 \r
441     /**\r
442      * Convert a datetime from the universal time scale stored as a <code>BigDecimal</code> to a\r
443      * <code>long</code> in the given time scale.\r
444      *\r
445      * Since this calculation requires a divide, we must round. The straight forward\r
446      * way to round by adding half of the divisor will push the sum out of range for values\r
447      * within have the divisor of the limits of the precision of a <code>long</code>. To get around this, we do\r
448      * the rounding like this:\r
449      * \r
450      * <p><code>\r
451      * (universalTime - units + units/2) / units + 1\r
452      * </code>\r
453      * \r
454      * <p>\r
455      * (i.e. we subtract units first to guarantee that we'll still be in range when we\r
456      * add <code>units/2</code>. We then need to add one to the quotent to make up for the extra subtraction.\r
457      * This simplifies to:\r
458      * \r
459      * <p><code>\r
460      * (universalTime - units/2) / units - 1\r
461      * </code>\r
462      * \r
463      * <p>\r
464      * For negative values to round away from zero, we need to flip the signs:\r
465      * \r
466      * <p><code>\r
467      * (universalTime + units/2) / units + 1\r
468      * </code>\r
469      * \r
470      * <p>\r
471      * Since we also need to subtract the epochOffset, we fold the <code>+/- 1</code>\r
472      * into the offset value. (i.e. <code>epochOffsetP1</code>, <code>epochOffsetM1</code>.)\r
473      * \r
474      * @param universalTime The datetime in the universal time scale\r
475      * @param timeScale The time scale to convert to\r
476      * \r
477      * @return The datetime converted to the given time scale\r
478      *\r
479      * @stable ICU 3.2\r
480      */\r
481     public static long toLong(long universalTime, int timeScale)\r
482     {\r
483         TimeScaleData data = toRangeCheck(universalTime, timeScale);\r
484         \r
485         if (universalTime < 0) {\r
486             if (universalTime < data.minRound) {\r
487                 return (universalTime + data.unitsRound) / data.units - data.epochOffsetP1;\r
488             }\r
489             \r
490             return (universalTime - data.unitsRound) / data.units - data.epochOffset;\r
491         }\r
492         \r
493         if (universalTime > data.maxRound) {\r
494             return (universalTime - data.unitsRound) / data.units - data.epochOffsetM1;\r
495         }\r
496         \r
497         return (universalTime + data.unitsRound) / data.units - data.epochOffset;\r
498     }\r
499     \r
500     /**\r
501      * Convert a datetime from the universal time scale to a <code>BigDecimal</code> in the given time scale.\r
502      *\r
503      * @param universalTime The datetime in the universal time scale\r
504      * @param timeScale The time scale to convert to\r
505      * \r
506      * @return The datetime converted to the given time scale\r
507      *\r
508      * @stable ICU 3.2\r
509      */\r
510     public static BigDecimal toBigDecimal(long universalTime, int timeScale)\r
511     {\r
512         TimeScaleData data     = getTimeScaleData(timeScale);\r
513         BigDecimal universal   = new BigDecimal(universalTime);\r
514         BigDecimal units       = new BigDecimal(data.units);\r
515         BigDecimal epochOffset = new BigDecimal(data.epochOffset);\r
516         \r
517         return universal.divide(units, BigDecimal.ROUND_HALF_UP).subtract(epochOffset);\r
518     }\r
519     \r
520     /**\r
521      * Convert a datetime from the universal time scale to a <code>BigDecimal</code> in the given time scale.\r
522      *\r
523      * @param universalTime The datetime in the universal time scale\r
524      * @param timeScale The time scale to convert to\r
525      * \r
526      * @return The datetime converted to the given time scale\r
527      *\r
528      * @stable ICU 3.2\r
529      */\r
530     public static BigDecimal toBigDecimal(BigDecimal universalTime, int timeScale)\r
531     {\r
532         TimeScaleData data     = getTimeScaleData(timeScale);\r
533         BigDecimal units       = new BigDecimal(data.units);\r
534         BigDecimal epochOffset = new BigDecimal(data.epochOffset);\r
535         \r
536         return universalTime.divide(units, BigDecimal.ROUND_HALF_UP).subtract(epochOffset);\r
537     }\r
538     \r
539     /**\r
540      * Return the <code>TimeScaleData</code> object for the given time\r
541      * scale.\r
542      * \r
543      * @param scale - the time scale\r
544      * @return the <code>TimeScaleData</code> object for the given time scale\r
545      */\r
546     private static TimeScaleData getTimeScaleData(int scale)\r
547     {\r
548         if (scale < 0 || scale >= MAX_SCALE) {\r
549             throw new IllegalArgumentException("scale out of range: " + scale);\r
550         }\r
551         \r
552         return timeScaleTable[scale];\r
553     }\r
554     \r
555     /**\r
556      * Get a value associated with a particular time scale.\r
557      * \r
558      * @param scale - the time scale\r
559      * @param value - a constant representing the value to get\r
560      * \r
561      * @return - the value.\r
562      * \r
563      * @stable ICU 3.2\r
564      */\r
565     public static long getTimeScaleValue(int scale, int value)\r
566     {\r
567         TimeScaleData data = getTimeScaleData(scale);\r
568         \r
569         switch (value)\r
570         {\r
571         case UNITS_VALUE:\r
572             return data.units;\r
573             \r
574         case EPOCH_OFFSET_VALUE:\r
575             return data.epochOffset;\r
576         \r
577         case FROM_MIN_VALUE:\r
578             return data.fromMin;\r
579             \r
580         case FROM_MAX_VALUE:\r
581             return data.fromMax;\r
582             \r
583         case TO_MIN_VALUE:\r
584             return data.toMin;\r
585             \r
586         case TO_MAX_VALUE:\r
587             return data.toMax;\r
588             \r
589         case EPOCH_OFFSET_PLUS_1_VALUE:\r
590             return data.epochOffsetP1;\r
591             \r
592         case EPOCH_OFFSET_MINUS_1_VALUE:\r
593             return data.epochOffsetM1;\r
594             \r
595         case UNITS_ROUND_VALUE:\r
596             return data.unitsRound;\r
597         \r
598         case MIN_ROUND_VALUE:\r
599             return data.minRound;\r
600             \r
601         case MAX_ROUND_VALUE:\r
602             return data.maxRound;\r
603             \r
604         default:\r
605             throw new IllegalArgumentException("value out of range: " + value);\r
606         }\r
607     }\r
608     \r
609     private static TimeScaleData toRangeCheck(long universalTime, int scale)\r
610     {\r
611         TimeScaleData data = getTimeScaleData(scale);\r
612           \r
613         if (universalTime >= data.toMin && universalTime <= data.toMax) {\r
614             return data;\r
615         }\r
616         \r
617         throw new IllegalArgumentException("universalTime out of range:" + universalTime);\r
618     }\r
619     \r
620     private static TimeScaleData fromRangeCheck(long otherTime, int scale)\r
621     {\r
622         TimeScaleData data = getTimeScaleData(scale);\r
623           \r
624         if (otherTime >= data.fromMin && otherTime <= data.fromMax) {\r
625             return data;\r
626         }\r
627         \r
628         throw new IllegalArgumentException("otherTime out of range:" + otherTime);\r
629     }\r
630     \r
631     /**\r
632      * Convert a time in the Universal Time Scale into another time\r
633      * scale. The division used to do the conversion rounds down.\r
634      * \r
635      * NOTE: This is an internal routine used by the tool that\r
636      * generates the to and from limits. Use it at your own risk.\r
637      * \r
638      * @param universalTime the time in the Universal Time scale\r
639      * @param timeScale the time scale to convert to\r
640      * @return the time in the given time scale\r
641      * \r
642      * @internal\r
643      * @deprecated This API is ICU internal only.\r
644      */\r
645     public static BigDecimal toBigDecimalTrunc(BigDecimal universalTime, int timeScale)\r
646     {\r
647         TimeScaleData data = getTimeScaleData(timeScale);\r
648         BigDecimal units = new BigDecimal(data.units);\r
649         BigDecimal epochOffset = new BigDecimal(data.epochOffset);\r
650         \r
651         return universalTime.divide(units, BigDecimal.ROUND_DOWN).subtract(epochOffset);\r
652     }\r
653 }\r