• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2title: Day-Period Design
3---
4
5# Day-Period Design
6
7## Problem:
8
9The two part AM/PM day division is not universal and some cultures require greater granularity in day divisions to properly represent a time. For more information, please see CLDR bugs [169](http://unicode.org/cldr/trac/ticket/168), [992](http://unicode.org/cldr/trac/ticket/992), [1935](http://unicode.org/cldr/trac/ticket/1935).
10
11## Proposal
12
13### New dayPeriods.xml under Supplemental directory:
14
15\<dayPeriodRuleSet>
16
17&emsp;\<dayPeriodRules locales = "locale1 locale2 ... ">
18
19&emsp;&emsp;\<dayPeriodRule type = "typeName1" from | after = "HH:mm" to | before = "HH:mm"/>
20
21&emsp;&emsp;\<dayPeriodRule type = "typeName2" at = "HH:mm"/>
22
23.....
24
25&emsp;\</dayPeriodRules>
26
27&emsp;\<dayPeriodRules locales = "..." >
28
29...
30
31&emsp;\</dayPeriodRules>
32
33\</dayPeriodRuleSet>
34
35### New XML rules in locale xmls :
36
37**\<dayPeriods>**
38
39&emsp;**\<dayPeriodContext type="format">**
40
41&emsp;&emsp;**\<dayPeriodWidth type="wide">**
42
43&emsp;&emsp;&emsp;\<**dayPeriod** type = "typeName1"> translation for typeName1\</dayPeriod>
44
45&emsp;&emsp;&emsp;\<**dayPeriod** type = "typeName2"> translation for typeName2\</dayPeriod>
46
47...
48
49&emsp;&emsp;\<**/dayPeriodWidth>**
50
51&emsp;**\</dayPeriodContext>**
52
53...
54
55**\</dayPeriods>**
56
57On "dayPeriods" in the future we can add an optional type if we need it, to support multiple rules for the same locale. For now we won't support that.
58
59### Definition and validation
60
611. If locales are not defined in dayPeriods.xml, dayPeriods fallback to AM/PM.
622. "from" and "to" are closed intervals(inclusive).
633. "after" and "before" are open intervals(exclusive).
644. "at" means starting time and end time are the same.
655. There must be exactly one of {at, from, after} and exactly one of {at, to, before} for each dayPeriodRule.
66	1. The set of dayPeriodRule's need to completely cover the 24 hours in a day (from 0:00 before 24:00), with **no** overlaps between each dayPeriodRule.
676. Both hh:mm [period name] and hh [period name] can be parsed uniquely to HH:mm [period name].
68	1. For example, you can't have \<dayPeriod type = "morning" from="0:00" to="12:00"/> because "12 {morning}" would be ambiguous.
697. One dayPeriodRule can cross midnight. For example:
70	1. \<dayPeriodRule type="night" from="20:00" before="5:00"/>
71	2. However, this should be avoided unless the alternative is awkward, because of ambiguities. While the use of the dayPeriods without hours is not recommended, they can be used. And if the user sees "Tuesday night" they may not think that that includes 1:00 am Tuesday.
72	3. dayPeriodRule's with the same type are only allowed if they are not adjacent. Example:
73	- \<dayPeriod type = "twilight" from="5:00" to="7:00"/>
74	- \<dayPeriod type = "twilight" from="17:00" to="19:00"/>
758. 24:00 is *only* allowed in *before*="24:00". A term for midnight should be avoided in the rules, because of ambiguity problems in most languages.
76	1. *"Tuesday midnight" generally means at the end of the day on Tuesday (24:00)*
77	2. *Most software does not format anything for 24:00, only for 00:00. And you don't want 00:00 Tuesday (the start of the day) to be formatted as midnight, meaning the end of the day.*
789. When parsing, if the hour is present the dayperiod is checked for consistency. If there is no hour, the center of the first matching dayPeriodRule is chosen (starting from 0:00).
7910. Document that if people are rounding -- including the rounding done by the time format -- then the rounding needs to be done before the dayperiod is computed.
80
81### Examples:
82
83New xml file: Supplemental/dayPeriods.xml
84
85\<dayPeriodRuleSet>
86
87&emsp;\<dayPeriodRules locales = "en"> \<!-- default for any locales not listed under other dayPeriods -->
88
89&emsp;&emsp;\<dayPeriodRule type = "am" from = "0:00" before="12:00"/>
90
91&emsp;&emsp;\<dayPeriodRule type = "pm" from = "12:00" to="24:00"/>
92
93&emsp;\</dayPeriodRules>
94
95&emsp;\<dayPeriodRules locales = "de it fr">
96
97&emsp;&emsp;\<dayPeriodRule type = "earlyMorning" from="0:00" before="9:00"/>
98
99&emsp;&emsp;\<dayPeriodRule type = "morning" from="9:00" before="12:00"/>
100
101&emsp;&emsp;\<dayPeriodRule type = "noon" at = "12:00"/>
102
103&emsp;&emsp;\<dayPeriodRule type = "afternoon" after="12:00" before="17:00"/>
104
105&emsp;&emsp;\<dayPeriodRule type = "evening" from="17:00" before="21:00"/>
106
107&emsp;&emsp;\<dayPeriodRule type = "night" from="21:00" before="24:00"/>
108
109&emsp;\</dayPeriodRules>
110
111&emsp;\<dayPeriodRules locales = "zh">
112
113&emsp;&emsp;\<dayPeriodRule type = "weeHours" from="00:00" before="4:00"/>
114
115&emsp;&emsp;\<dayPeriodRule type = "earlyMorning" from="4:00" before="6:00"/>
116
117&emsp;&emsp;\<dayPeriodRule type = "morning" from="6:00" before="12:00"/>
118
119&emsp;&emsp;\<dayPeriodRule type = "midMay" from="12:00" before="13:00"/>
120
121&emsp;&emsp;\<dayPeriodRule type = "afternoon" from="13:00" before="18:00"/>
122
123&emsp;&emsp;\<dayPeriodRule type = "night" from="18:00" before="24:00"/>
124
125&emsp;\</dayPeriodRules>
126
127**. . .**
128
129\</dayPeriodRuleSet>
130
131Examples in locale XML files:
132
133In en locale file(en.xml)
134
135\<dayPeriods>
136
137&emsp;**\<dayPeriodContext type="format">**
138
139&emsp;&emsp;**\<dayPeriodWidth type="wide">**
140
141&emsp;&emsp;&emsp;\<dayPeriod type = "am">AM\</dayPeriod>
142
143&emsp;&emsp;&emsp;\<dayPeriod type = "am" alt="variant">a.m.\</dayPeriod>
144
145&emsp;&emsp;&emsp;\<dayPeriod type = "pm">PM\</dayPeriod>
146
147&emsp;&emsp;&emsp;\<dayPeriod type = "pm" alt="variant">p.m.\</dayPeriod>
148
149&emsp;&emsp;\<**/dayPeriodWidth>**
150
151&emsp;**\</dayPeriodContext>**
152
153\</dayPeriods>
154
155// was:
156
157&emsp;&emsp;\<am>AM\</am>
158
159&emsp;&emsp;\<am alt="variant">a.m.\</am>
160
161&emsp;&emsp;\<pm>PM\</pm>
162
163&emsp;&emsp;\<pm alt="variant">p.m.\</pm>
164
165*Also, in root, replace all instances (except in Gregorian) of*
166
167&emsp;&emsp;\<am>AM\</am>
168
169&emsp;&emsp;\<pm>PM\</pm>
170
171*by*
172
173&emsp;&emsp;\<dayPeriods>
174
175&emsp;&emsp;&emsp;\<alias source="locale" path="../../calendar[@type='gregorian']/dayPeriods"/>
176
177&emsp;&emsp;\</dayPeriods>
178
179In de locale file(de.xml):
180
181\<dayPeriods>
182
183&emsp;**\<dayPeriodContext type="format">**
184
185&emsp;&emsp;**\<dayPeriodWidth type="wide">**
186
187&emsp;&emsp;&emsp;\<dayPeriod type = "earlyMorning">morgens\</dayPeriod>
188
189&emsp;&emsp;&emsp;\<dayPeriod type = "morning">vormittags\</dayPeriod>
190
191&emsp;&emsp;&emsp;\<dayPeriod type = "noon">Mittag\</dayPeriod>
192
193&emsp;&emsp;&emsp;\<dayPeriod type = "afternoon">nachmittags\</dayPeriod>
194
195&emsp;&emsp;&emsp;\<dayPeriod type = "evening">abends\</dayPeriod>
196
197&emsp;&emsp;&emsp;\<dayPeriod type = "night">nachts\</dayPeriod>
198
199&emsp;&emsp;\<**/dayPeriodWidth>**
200
201&emsp;**\</dayPeriodContext>**
202
203\</dayPeriods>
204
205
206
207In zh locale file(zh.xml):
208
209\<dayPeriods>
210
211&emsp;**\<dayPeriodContext type="format">**
212
213&emsp;&emsp;**\<dayPeriodWidth type="wide">**
214
215&emsp;&emsp;&emsp;\<dayPeriod type = "weeHours">凌晨\</dayPeriod>
216
217&emsp;&emsp;&emsp;\<dayPeriod type = "earlyMorning">清晨\</dayPeriod>
218
219&emsp;&emsp;&emsp;\<dayPeriod type = "morning">上午\</dayPeriod>
220
221&emsp;&emsp;&emsp;\<dayPeriod type = "midDay">中午\</dayPeriod>
222
223&emsp;&emsp;&emsp;\<dayPeriod type = "afternoon">下午\</dayPeriod>
224
225&emsp;&emsp;&emsp;\<dayPeriod type = "night">晚上\</dayPeriod>
226
227&emsp;&emsp;\<**/dayPeriodWidth>**
228
229&emsp;**\</dayPeriodContext>**
230
231\</dayPeriods>
232
233Code changes
234
235- The example code needs to be changed to get the AM/PM data from the new location (high priority)
236- LDML2ICU needs to change to map the new data.
237- ICU code needs to use the new structure
238- We need to have a chart for the dayPeriodRules, like we do for plurals.
239- Add invariant testing in CheckAttributes.
240
241