2 *******************************************************************************
3 * Copyright (C) 2016, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
8 * created on: 2016-01-20
12 #ifndef DAYPERIODRULES_H
13 #define DAYPERIODRULES_H
15 #include "unicode/locid.h"
16 #include "unicode/unistr.h"
17 #include "unicode/uobject.h"
18 #include "unicode/utypes.h"
26 struct DayPeriodRulesDataSink
;
28 class DayPeriodRules
: public UMemory
{
29 friend struct DayPeriodRulesDataSink
;
32 DAYPERIOD_UNKNOWN
= -1,
47 static const DayPeriodRules
*getInstance(const Locale
&locale
, UErrorCode
&errorCode
);
49 UBool
hasMidnight() const { return fHasMidnight
; }
50 UBool
hasNoon() const { return fHasNoon
; }
51 DayPeriod
getDayPeriodForHour(int32_t hour
) const { return fDayPeriodForHour
[hour
]; }
53 // Returns the center of dayPeriod. Half hours are indicated with a .5 .
54 double getMidPointForDayPeriod(DayPeriod dayPeriod
, UErrorCode
&errorCode
) const;
59 // Translates "morning1" to DAYPERIOD_MORNING1, for example.
60 static DayPeriod
getDayPeriodFromString(const char *type_str
);
62 static void load(UErrorCode
&errorCode
);
64 // Sets period type for all hours in [startHour, limitHour).
65 void add(int32_t startHour
, int32_t limitHour
, DayPeriod period
);
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();
71 // Returns the hour that starts dayPeriod. Returns 0 for MIDNIGHT and 12 for NOON.
72 int32_t getStartHourForDayPeriod(DayPeriod dayPeriod
, UErrorCode
&errorCode
) const;
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;
82 DayPeriod fDayPeriodForHour
[24];
87 #endif /* DAYPERIODRULES_H */