You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -134,43 +125,36 @@ Note: the following steps are currently only possible in Rust. 🤷
134
125
When we ran `icu4x-datagen`, we passed `--markers all`, which make it generate *all* data for the Chakma locale, even though we only need date formatting. We can make `icu4x-datagen` analyze our binary to figure out which markers are needed:
Note: you usually want to build with the `--release` flag, and analyze that binary, but we don't have all day.
132
+
Note: you usually want to build with the `--release` flag, and analyze that binary.
141
133
142
134
This should generate a lot fewer markers!
143
135
144
136
Let's look at the sizes:
145
137
146
138
```console
147
139
wc -c *.blob
148
-
# 656767 ccp.blob
149
-
# 45471 ccp_smaller.blob
140
+
# 5448603 ccp.blob
141
+
# 13711 ccp_smaller.blob
150
142
```
151
143
152
144
This is much better! Rerun your app with `ccp_smaller.blob` to make sure it still works!
153
145
154
146
## 5. Slimming the data pack ... again
155
147
156
-
The last datagen invocation still produced a lot of markers, as you saw in its output. This is because we used the `DateFormatter` API, which can format dates for a lot of different calendars. However, if we are only using it with an Gregorian calendar date, so we don't need Coptic, Indian, etc. date formatting data.
148
+
The last datagen invocation still produced a lot of markers, as you saw in its output. This is because we used the `DateTimeFormatter` API, which can format dates for a lot of different calendars (remember `en-u-ca-hebrew`). However, if we were only using it with a Gregorian calendar date, we wouldn't need Coptic, Indian, etc. date formatting data. Now, how do we communicate this to `--markers-for-bin`? Turns out, `icu::datetime` also exposes a `FixedCalendarDateTimeFormatter`, which is generic in a single calendar type. If you use this API instead, `--markers-for-bin` will only include the markers for that one calendar type.
157
149
158
-
We've seen that `DateFormatter` pulls in a lot of data. It would be nice if we could tell it that we'll only ever use it with Gregorian dates. Turns out we can! `icu::datetime` also exposes a `TypedDateFormatter<C>`, which is generic in a single calendar type. If you use this API instead (instantiated as `TypedDateFormatter<Gregorian>`), `--markers-for-bin` will give you exactly the markers we manually selected in the last section. However, now you can be sure that you didn't make a mistake selecting the markers (which would be an awkward runtime error), and that you will never accidentally pass a non-Gregorian date into the formatter (which would an awkward runtime error with `DateFormatter`, but is a compile-time error with `TypeDateFormatter`).
150
+
Replace the `DateTimeFormatter::try_new` calls with `FixedCalendarDateTimeFormatter::try_new`, and change the `format` invocation to convert the input to the Gregorian calendar:
The generic type of `FixedCalendarDateTimeFormatter` will be inferred from the input, which now has type `&Date<Gregorian>` now. Unlike `DateTimeFormatter`, `FixedCalendarDateTimeFormatter` never applies calendar conversions on its input, so it will be a `FixedCalendarDateTimeFormatter<Gregorian, ...>`.
157
+
174
158
Now we can run datagen with `--markers-for-bin` again:
0 commit comments