intl/icu/source/i18n/utmscale.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 *******************************************************************************
michael@0 3 * Copyright (C) 2004-2012, International Business Machines Corporation and
michael@0 4 * others. All Rights Reserved.
michael@0 5 *******************************************************************************
michael@0 6 */
michael@0 7
michael@0 8 #include "unicode/utypes.h"
michael@0 9
michael@0 10 #if !UCONFIG_NO_FORMATTING
michael@0 11
michael@0 12 #include "unicode/utmscale.h"
michael@0 13
michael@0 14 #define ticks INT64_C(1)
michael@0 15 #define microseconds (ticks * 10)
michael@0 16 #define milliseconds (microseconds * 1000)
michael@0 17 #define seconds (milliseconds * 1000)
michael@0 18 #define minutes (seconds * 60)
michael@0 19 #define hours (minutes * 60)
michael@0 20 #define days (hours * 24)
michael@0 21
michael@0 22 /* Constants generated by ICU4J com.ibm.icu.dev.tool.timescale.GenerateCTimeScaleData. */
michael@0 23 static const int64_t timeScaleTable[UDTS_MAX_SCALE][UTSV_MAX_SCALE_VALUE] = {
michael@0 24 /* units epochOffset fromMin fromMax toMin toMax epochOffsetP1 epochOffsetM1 unitsRound minRound maxRound */
michael@0 25 {milliseconds, INT64_C(62135596800000), INT64_C(-984472800485477), INT64_C(860201606885477), INT64_C(-9223372036854774999), INT64_C(9223372036854774999), INT64_C(62135596800001), INT64_C(62135596799999), INT64_C(5000), INT64_C(-9223372036854770808), INT64_C(9223372036854770807)},
michael@0 26 {seconds, INT64_C(62135596800), INT64_C(-984472800485), INT64_C(860201606885), U_INT64_MIN, U_INT64_MAX, INT64_C(62135596801), INT64_C(62135596799), INT64_C(5000000), INT64_C(-9223372036849775808), INT64_C(9223372036849775807)},
michael@0 27 {milliseconds, INT64_C(62135596800000), INT64_C(-984472800485477), INT64_C(860201606885477), INT64_C(-9223372036854774999), INT64_C(9223372036854774999), INT64_C(62135596800001), INT64_C(62135596799999), INT64_C(5000), INT64_C(-9223372036854770808), INT64_C(9223372036854770807)},
michael@0 28 {ticks, INT64_C(504911232000000000), U_INT64_MIN, INT64_C(8718460804854775807), INT64_C(-8718460804854775808), U_INT64_MAX, INT64_C(504911232000000000), INT64_C(504911232000000000), INT64_C(0), U_INT64_MIN, U_INT64_MAX},
michael@0 29 {ticks, INT64_C(0), U_INT64_MIN, U_INT64_MAX, U_INT64_MIN, U_INT64_MAX, INT64_C(0), INT64_C(0), INT64_C(0), U_INT64_MIN, U_INT64_MAX},
michael@0 30 {seconds, INT64_C(60052752000), INT64_C(-982389955685), INT64_C(862284451685), U_INT64_MIN, U_INT64_MAX, INT64_C(60052752001), INT64_C(60052751999), INT64_C(5000000), INT64_C(-9223372036849775808), INT64_C(9223372036849775807)},
michael@0 31 {seconds, INT64_C(63113904000), INT64_C(-985451107685), INT64_C(859223299685), U_INT64_MIN, U_INT64_MAX, INT64_C(63113904001), INT64_C(63113903999), INT64_C(5000000), INT64_C(-9223372036849775808), INT64_C(9223372036849775807)},
michael@0 32 {days, INT64_C(693594), INT64_C(-11368793), INT64_C(9981605), U_INT64_MIN, U_INT64_MAX, INT64_C(693595), INT64_C(693593), INT64_C(432000000000), INT64_C(-9223371604854775808), INT64_C(9223371604854775807)},
michael@0 33 {days, INT64_C(693594), INT64_C(-11368793), INT64_C(9981605), U_INT64_MIN, U_INT64_MAX, INT64_C(693595), INT64_C(693593), INT64_C(432000000000), INT64_C(-9223371604854775808), INT64_C(9223371604854775807)},
michael@0 34 {microseconds, INT64_C(62135596800000000), INT64_C(-984472800485477580), INT64_C(860201606885477580), INT64_C(-9223372036854775804), INT64_C(9223372036854775804), INT64_C(62135596800000001), INT64_C(62135596799999999), INT64_C(5), INT64_C(-9223372036854775803), INT64_C(9223372036854775802)},
michael@0 35 };
michael@0 36
michael@0 37 U_CAPI int64_t U_EXPORT2
michael@0 38 utmscale_getTimeScaleValue(UDateTimeScale timeScale, UTimeScaleValue value, UErrorCode *status)
michael@0 39 {
michael@0 40 if (status == NULL || U_FAILURE(*status)) {
michael@0 41 return 0;
michael@0 42 }
michael@0 43
michael@0 44 if (timeScale < UDTS_JAVA_TIME || UDTS_MAX_SCALE <= timeScale
michael@0 45 || value < UTSV_UNITS_VALUE || UTSV_MAX_SCALE_VALUE <= value)
michael@0 46 {
michael@0 47 *status = U_ILLEGAL_ARGUMENT_ERROR;
michael@0 48 return 0;
michael@0 49 }
michael@0 50
michael@0 51 return timeScaleTable[timeScale][value];
michael@0 52 }
michael@0 53
michael@0 54 U_CAPI int64_t U_EXPORT2
michael@0 55 utmscale_fromInt64(int64_t otherTime, UDateTimeScale timeScale, UErrorCode *status)
michael@0 56 {
michael@0 57 const int64_t *data;
michael@0 58
michael@0 59 if (status == NULL || U_FAILURE(*status)) {
michael@0 60 return 0;
michael@0 61 }
michael@0 62
michael@0 63 if ((int32_t)timeScale < 0 || timeScale >= UDTS_MAX_SCALE) {
michael@0 64 *status = U_ILLEGAL_ARGUMENT_ERROR;
michael@0 65 return 0;
michael@0 66 }
michael@0 67
michael@0 68 data = (const int64_t *)(&timeScaleTable[timeScale]);
michael@0 69
michael@0 70 if (otherTime < data[UTSV_FROM_MIN_VALUE] || otherTime > data[UTSV_FROM_MAX_VALUE]) {
michael@0 71 *status = U_ILLEGAL_ARGUMENT_ERROR;
michael@0 72 return 0;
michael@0 73 }
michael@0 74
michael@0 75 return (otherTime + data[UTSV_EPOCH_OFFSET_VALUE]) * data[UTSV_UNITS_VALUE];
michael@0 76 }
michael@0 77
michael@0 78 U_CAPI int64_t U_EXPORT2
michael@0 79 utmscale_toInt64(int64_t universalTime, UDateTimeScale timeScale, UErrorCode *status)
michael@0 80 {
michael@0 81 const int64_t *data;
michael@0 82
michael@0 83 if (status == NULL || U_FAILURE(*status)) {
michael@0 84 return 0;
michael@0 85 }
michael@0 86
michael@0 87 if ((int32_t)timeScale < 0 || timeScale >= UDTS_MAX_SCALE) {
michael@0 88 *status = U_ILLEGAL_ARGUMENT_ERROR;
michael@0 89 return 0;
michael@0 90 }
michael@0 91
michael@0 92 data = (const int64_t *)(&timeScaleTable[timeScale]);
michael@0 93
michael@0 94 if (universalTime < data[UTSV_TO_MIN_VALUE] || universalTime > data[UTSV_TO_MAX_VALUE]) {
michael@0 95 *status = U_ILLEGAL_ARGUMENT_ERROR;
michael@0 96 return 0;
michael@0 97 }
michael@0 98
michael@0 99 if (universalTime < 0) {
michael@0 100 if (universalTime < data[UTSV_MIN_ROUND_VALUE]) {
michael@0 101 return (universalTime + data[UTSV_UNITS_ROUND_VALUE]) / data[UTSV_UNITS_VALUE] - data[UTSV_EPOCH_OFFSET_PLUS_1_VALUE];
michael@0 102 }
michael@0 103
michael@0 104 return (universalTime - data[UTSV_UNITS_ROUND_VALUE]) / data[UTSV_UNITS_VALUE] - data[UTSV_EPOCH_OFFSET_VALUE];
michael@0 105 }
michael@0 106
michael@0 107 if (universalTime > data[UTSV_MAX_ROUND_VALUE]) {
michael@0 108 return (universalTime - data[UTSV_UNITS_ROUND_VALUE]) / data[UTSV_UNITS_VALUE] - data[UTSV_EPOCH_OFFSET_MINUS_1_VALUE];
michael@0 109 }
michael@0 110
michael@0 111 return (universalTime + data[UTSV_UNITS_ROUND_VALUE]) / data[UTSV_UNITS_VALUE] - data[UTSV_EPOCH_OFFSET_VALUE];
michael@0 112 }
michael@0 113
michael@0 114 #endif /* #if !UCONFIG_NO_FORMATTING */

mercurial