1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 * created on: 2016-01-20
14 #ifndef DAYPERIODRULES_H
15 #define DAYPERIODRULES_H
17 #include "unicode/locid.h"
18 #include "unicode/unistr.h"
19 #include "unicode/uobject.h"
20 #include "unicode/utypes.h"
28 struct DayPeriodRulesDataSink;
30 class DayPeriodRules : public UMemory {
31 friend struct DayPeriodRulesDataSink;
34 DAYPERIOD_UNKNOWN = -1,
49 static const DayPeriodRules *getInstance(const Locale &locale, UErrorCode &errorCode);
51 UBool hasMidnight() const { return fHasMidnight; }
52 UBool hasNoon() const { return fHasNoon; }
53 DayPeriod getDayPeriodForHour(int32_t hour) const { return fDayPeriodForHour[hour]; }
55 // Returns the center of dayPeriod. Half hours are indicated with a .5 .
56 double getMidPointForDayPeriod(DayPeriod dayPeriod, UErrorCode &errorCode) const;
61 // Translates "morning1" to DAYPERIOD_MORNING1, for example.
62 static DayPeriod getDayPeriodFromString(const char *type_str);
64 static void U_CALLCONV load(UErrorCode &errorCode);
66 // Sets period type for all hours in [startHour, limitHour).
67 void add(int32_t startHour, int32_t limitHour, DayPeriod period);
69 // Returns TRUE if for all i, DayPeriodForHour[i] has a type other than UNKNOWN.
70 // Values of HasNoon and HasMidnight do not affect the return value.
71 UBool allHoursAreSet();
73 // Returns the hour that starts dayPeriod. Returns 0 for MIDNIGHT and 12 for NOON.
74 int32_t getStartHourForDayPeriod(DayPeriod dayPeriod, UErrorCode &errorCode) const;
76 // Returns the hour that ends dayPeriod, i.e. that starts the next period.
77 // E.g. if fDayPeriodForHour[13] thru [16] are AFTERNOON1, then this function returns 17 if
78 // queried with AFTERNOON1.
79 // Returns 0 for MIDNIGHT and 12 for NOON.
80 int32_t getEndHourForDayPeriod(DayPeriod dayPeriod, UErrorCode &errorCode) const;
84 DayPeriod fDayPeriodForHour[24];
89 #endif /* DAYPERIODRULES_H */