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 \<dayPeriodRules locales = "locale1 locale2 ... "> 18 19  \<dayPeriodRule type = "typeName1" from | after = "HH:mm" to | before = "HH:mm"/> 20 21  \<dayPeriodRule type = "typeName2" at = "HH:mm"/> 22 23..... 24 25 \</dayPeriodRules> 26 27 \<dayPeriodRules locales = "..." > 28 29... 30 31 \</dayPeriodRules> 32 33\</dayPeriodRuleSet> 34 35### New XML rules in locale xmls : 36 37**\<dayPeriods>** 38 39 **\<dayPeriodContext type="format">** 40 41  **\<dayPeriodWidth type="wide">** 42 43   \<**dayPeriod** type = "typeName1"> translation for typeName1\</dayPeriod> 44 45   \<**dayPeriod** type = "typeName2"> translation for typeName2\</dayPeriod> 46 47... 48 49  \<**/dayPeriodWidth>** 50 51 **\</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 \<dayPeriodRules locales = "en"> \<!-- default for any locales not listed under other dayPeriods --> 88 89  \<dayPeriodRule type = "am" from = "0:00" before="12:00"/> 90 91  \<dayPeriodRule type = "pm" from = "12:00" to="24:00"/> 92 93 \</dayPeriodRules> 94 95 \<dayPeriodRules locales = "de it fr"> 96 97  \<dayPeriodRule type = "earlyMorning" from="0:00" before="9:00"/> 98 99  \<dayPeriodRule type = "morning" from="9:00" before="12:00"/> 100 101  \<dayPeriodRule type = "noon" at = "12:00"/> 102 103  \<dayPeriodRule type = "afternoon" after="12:00" before="17:00"/> 104 105  \<dayPeriodRule type = "evening" from="17:00" before="21:00"/> 106 107  \<dayPeriodRule type = "night" from="21:00" before="24:00"/> 108 109 \</dayPeriodRules> 110 111 \<dayPeriodRules locales = "zh"> 112 113  \<dayPeriodRule type = "weeHours" from="00:00" before="4:00"/> 114 115  \<dayPeriodRule type = "earlyMorning" from="4:00" before="6:00"/> 116 117  \<dayPeriodRule type = "morning" from="6:00" before="12:00"/> 118 119  \<dayPeriodRule type = "midMay" from="12:00" before="13:00"/> 120 121  \<dayPeriodRule type = "afternoon" from="13:00" before="18:00"/> 122 123  \<dayPeriodRule type = "night" from="18:00" before="24:00"/> 124 125 \</dayPeriodRules> 126 127**. . .** 128 129\</dayPeriodRuleSet> 130 131Examples in locale XML files: 132 133In en locale file(en.xml) 134 135\<dayPeriods> 136 137 **\<dayPeriodContext type="format">** 138 139  **\<dayPeriodWidth type="wide">** 140 141   \<dayPeriod type = "am">AM\</dayPeriod> 142 143   \<dayPeriod type = "am" alt="variant">a.m.\</dayPeriod> 144 145   \<dayPeriod type = "pm">PM\</dayPeriod> 146 147   \<dayPeriod type = "pm" alt="variant">p.m.\</dayPeriod> 148 149  \<**/dayPeriodWidth>** 150 151 **\</dayPeriodContext>** 152 153\</dayPeriods> 154 155// was: 156 157  \<am>AM\</am> 158 159  \<am alt="variant">a.m.\</am> 160 161  \<pm>PM\</pm> 162 163  \<pm alt="variant">p.m.\</pm> 164 165*Also, in root, replace all instances (except in Gregorian) of* 166 167  \<am>AM\</am> 168 169  \<pm>PM\</pm> 170 171*by* 172 173  \<dayPeriods> 174 175   \<alias source="locale" path="../../calendar[@type='gregorian']/dayPeriods"/> 176 177  \</dayPeriods> 178 179In de locale file(de.xml): 180 181\<dayPeriods> 182 183 **\<dayPeriodContext type="format">** 184 185  **\<dayPeriodWidth type="wide">** 186 187   \<dayPeriod type = "earlyMorning">morgens\</dayPeriod> 188 189   \<dayPeriod type = "morning">vormittags\</dayPeriod> 190 191   \<dayPeriod type = "noon">Mittag\</dayPeriod> 192 193   \<dayPeriod type = "afternoon">nachmittags\</dayPeriod> 194 195   \<dayPeriod type = "evening">abends\</dayPeriod> 196 197   \<dayPeriod type = "night">nachts\</dayPeriod> 198 199  \<**/dayPeriodWidth>** 200 201 **\</dayPeriodContext>** 202 203\</dayPeriods> 204 205 206 207In zh locale file(zh.xml): 208 209\<dayPeriods> 210 211 **\<dayPeriodContext type="format">** 212 213  **\<dayPeriodWidth type="wide">** 214 215   \<dayPeriod type = "weeHours">凌晨\</dayPeriod> 216 217   \<dayPeriod type = "earlyMorning">清晨\</dayPeriod> 218 219   \<dayPeriod type = "morning">上午\</dayPeriod> 220 221   \<dayPeriod type = "midDay">中午\</dayPeriod> 222 223   \<dayPeriod type = "afternoon">下午\</dayPeriod> 224 225   \<dayPeriod type = "night">晚上\</dayPeriod> 226 227  \<**/dayPeriodWidth>** 228 229 **\</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