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