]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/dayperiodrules.h
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / dayperiodrules.h
1 /*
2 *******************************************************************************
3 * Copyright (C) 2016, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * dayperiodrules.h
7 *
8 * created on: 2016-01-20
9 * created by: kazede
10 */
11
12 #ifndef DAYPERIODRULES_H
13 #define DAYPERIODRULES_H
14
15 #include "unicode/locid.h"
16 #include "unicode/unistr.h"
17 #include "unicode/uobject.h"
18 #include "unicode/utypes.h"
19 #include "resource.h"
20 #include "uhash.h"
21
22
23
24 U_NAMESPACE_BEGIN
25
26 struct DayPeriodRulesDataSink;
27
28 class DayPeriodRules : public UMemory {
29 friend struct DayPeriodRulesDataSink;
30 public:
31 enum DayPeriod {
32 DAYPERIOD_UNKNOWN = -1,
33 DAYPERIOD_MIDNIGHT,
34 DAYPERIOD_NOON,
35 DAYPERIOD_MORNING1,
36 DAYPERIOD_AFTERNOON1,
37 DAYPERIOD_EVENING1,
38 DAYPERIOD_NIGHT1,
39 DAYPERIOD_MORNING2,
40 DAYPERIOD_AFTERNOON2,
41 DAYPERIOD_EVENING2,
42 DAYPERIOD_NIGHT2,
43 DAYPERIOD_AM,
44 DAYPERIOD_PM
45 };
46
47 static const DayPeriodRules *getInstance(const Locale &locale, UErrorCode &errorCode);
48
49 UBool hasMidnight() const { return fHasMidnight; }
50 UBool hasNoon() const { return fHasNoon; }
51 DayPeriod getDayPeriodForHour(int32_t hour) const { return fDayPeriodForHour[hour]; }
52
53 // Returns the center of dayPeriod. Half hours are indicated with a .5 .
54 double getMidPointForDayPeriod(DayPeriod dayPeriod, UErrorCode &errorCode) const;
55
56 private:
57 DayPeriodRules();
58
59 // Translates "morning1" to DAYPERIOD_MORNING1, for example.
60 static DayPeriod getDayPeriodFromString(const char *type_str);
61
62 static void load(UErrorCode &errorCode);
63
64 // Sets period type for all hours in [startHour, limitHour).
65 void add(int32_t startHour, int32_t limitHour, DayPeriod period);
66
67 // Returns TRUE if for all i, DayPeriodForHour[i] has a type other than UNKNOWN.
68 // Values of HasNoon and HasMidnight do not affect the return value.
69 UBool allHoursAreSet();
70
71 // Returns the hour that starts dayPeriod. Returns 0 for MIDNIGHT and 12 for NOON.
72 int32_t getStartHourForDayPeriod(DayPeriod dayPeriod, UErrorCode &errorCode) const;
73
74 // Returns the hour that ends dayPeriod, i.e. that starts the next period.
75 // E.g. if fDayPeriodForHour[13] thru [16] are AFTERNOON1, then this function returns 17 if
76 // queried with AFTERNOON1.
77 // Returns 0 for MIDNIGHT and 12 for NOON.
78 int32_t getEndHourForDayPeriod(DayPeriod dayPeriod, UErrorCode &errorCode) const;
79
80 UBool fHasMidnight;
81 UBool fHasNoon;
82 DayPeriod fDayPeriodForHour[24];
83 };
84
85 U_NAMESPACE_END
86
87 #endif /* DAYPERIODRULES_H */