Skip to content

Commit 90939c0

Browse files
authored
Add withEra (#1016)
* Add era * add changelog * add pages workflow * fix * fix path * add permission * new versions * Fix era in JS * tighten constraints * run on main only
1 parent 34d1832 commit 90939c0

File tree

9 files changed

+174
-71
lines changed

9 files changed

+174
-71
lines changed

.github/workflows/intl4x.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: package:intl4x
22
permissions:
33
pull-requests: read # Changed to read, as we are only reading labels
44
contents: read # Added for checkout action
5+
pages: write # For the dart doc page job
6+
id-token: write
57

68
on:
79
pull_request:
@@ -100,3 +102,43 @@ jobs:
100102
Write-Host "Error: Windows executable size ($fileSize bytes) exceeds 10MB limit (10485760 bytes)."
101103
exit 1
102104
}
105+
106+
docs:
107+
if: ${{ github.event_name == 'push' }}
108+
runs-on: ubuntu-latest
109+
110+
defaults:
111+
run:
112+
working-directory: pkgs/intl4x
113+
steps:
114+
- name: Checkout Repository
115+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
116+
117+
- name: Setup Dart SDK
118+
uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
119+
with:
120+
sdk: main
121+
122+
- name: Install dependencies
123+
run: dart pub get
124+
125+
- name: Generate Documentation
126+
run: dart doc
127+
128+
- name: Upload Documentation Artifact
129+
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b
130+
with:
131+
path: pkgs/intl4x/doc/api/
132+
133+
deploy:
134+
if: ${{ github.event_name == 'push' }}
135+
environment:
136+
name: github-pages
137+
url: ${{ steps.deployment.outputs.page_url }}
138+
runs-on: ubuntu-latest
139+
needs: docs
140+
141+
steps:
142+
- name: Deploy to GitHub Pages
143+
id: deployment
144+
uses: actions/deploy-pages@854d7aa1b99e4509c4d1b53d69b7ba4eaf39215a

pkgs/intl4x/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.13.2
2+
3+
- Add `withEra`.
4+
15
## 0.13.1
26

37
- Fix casemapping on the web.

pkgs/intl4x/lib/src/datetime_format/datetime_format.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ class DateTimeFormatBuilder {
2929
DateTimeFormatter m({DateFormatStyle? dateStyle}) =>
3030
_impl.m(dateStyle: dateStyle);
3131

32-
DateTimeFormatter y({DateFormatStyle? dateStyle}) =>
33-
_impl.y(dateStyle: dateStyle);
32+
DateTimeFormatter y({DateFormatStyle? dateStyle, bool withEra = false}) =>
33+
_impl.y(dateStyle: dateStyle, withEra: withEra);
3434

3535
DateTimeFormatter md({DateFormatStyle? dateStyle}) =>
3636
_impl.md(dateStyle: dateStyle);
3737

38-
DateTimeFormatter ymd({DateFormatStyle? dateStyle}) =>
39-
_impl.ymd(dateStyle: dateStyle);
38+
DateTimeFormatter ymd({DateFormatStyle? dateStyle, bool withEra = false}) =>
39+
_impl.ymd(dateStyle: dateStyle, withEra: withEra);
4040

41-
DateTimeFormatter ymde({DateFormatStyle? dateStyle}) =>
42-
_impl.ymde(dateStyle: dateStyle);
41+
DateTimeFormatter ymde({DateFormatStyle? dateStyle, bool withEra = false}) =>
42+
_impl.ymde(dateStyle: dateStyle, withEra: withEra);
4343

4444
DateTimeFormatter mdt({
4545
DateFormatStyle? dateStyle,
@@ -49,12 +49,16 @@ class DateTimeFormatBuilder {
4949
DateTimeFormatter ymdt({
5050
DateFormatStyle? dateStyle,
5151
TimeFormatStyle? timeStyle,
52-
}) => _impl.ymdt(timeStyle: timeStyle, dateStyle: dateStyle);
52+
bool withEra = false,
53+
}) =>
54+
_impl.ymdt(timeStyle: timeStyle, dateStyle: dateStyle, withEra: withEra);
5355

5456
DateTimeFormatter ymdet({
5557
DateFormatStyle? dateStyle,
5658
TimeFormatStyle? timeStyle,
57-
}) => _impl.ymdet(timeStyle: timeStyle, dateStyle: dateStyle);
59+
bool withEra = false,
60+
}) =>
61+
_impl.ymdet(timeStyle: timeStyle, dateStyle: dateStyle, withEra: withEra);
5862

5963
DateTimeFormatter t({TimeFormatStyle? style}) => _impl.t(style: style);
6064
}

pkgs/intl4x/lib/src/datetime_format/datetime_format_ecma.dart

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,19 @@ class FormatterECMA extends FormatterImpl {
6868
final DateTimeFormat dateTimeFormat;
6969
final TimeFormatStyle? timeStyle;
7070
final DateFormatStyle? dateStyle;
71+
final bool withEra;
7172

7273
FormatterECMA(
7374
this.impl,
7475
this.optionsJS,
7576
this.locale,
7677
this.options, {
77-
required this.timeStyle,
78-
required this.dateStyle,
78+
this.timeStyle,
79+
this.dateStyle,
80+
required this.withEra,
7981
}) : dateTimeFormat = DateTimeFormat(
8082
[locale.toLanguageTag().toJS].toJS,
81-
options.toJsMap(optionsJS, timeStyle, dateStyle),
83+
options.toJsMap(optionsJS, timeStyle, dateStyle, withEra),
8284
),
8385
super(impl);
8486

@@ -132,6 +134,7 @@ class FormatterZonedECMA extends FormatterZonedImpl {
132134
),
133135
formatter.timeStyle,
134136
formatter.dateStyle,
137+
formatter.withEra,
135138
),
136139
);
137140
}
@@ -172,6 +175,7 @@ class _DateTimeFormatECMA extends DateTimeFormatImpl {
172175
options,
173176
timeStyle: null,
174177
dateStyle: dateStyle,
178+
withEra: false,
175179
);
176180

177181
@override
@@ -186,6 +190,7 @@ class _DateTimeFormatECMA extends DateTimeFormatImpl {
186190
options,
187191
timeStyle: null,
188192
dateStyle: dateStyle,
193+
withEra: false,
189194
);
190195

191196
@override
@@ -200,6 +205,7 @@ class _DateTimeFormatECMA extends DateTimeFormatImpl {
200205
options,
201206
timeStyle: null,
202207
dateStyle: dateStyle,
208+
withEra: false,
203209
);
204210

205211
@override
@@ -213,46 +219,54 @@ class _DateTimeFormatECMA extends DateTimeFormatImpl {
213219
options,
214220
timeStyle: style,
215221
dateStyle: null,
222+
withEra: false,
216223
);
217224

218225
@override
219-
FormatterImpl y({DateFormatStyle? dateStyle}) => FormatterECMA(
220-
this,
221-
DateTimeJSOptions(year: _timeStyle(null, dateStyle)),
222-
locale,
223-
options,
224-
timeStyle: null,
225-
dateStyle: dateStyle,
226-
);
226+
FormatterImpl y({DateFormatStyle? dateStyle, bool withEra = false}) =>
227+
FormatterECMA(
228+
this,
229+
DateTimeJSOptions(year: _timeStyle(null, dateStyle)),
230+
locale,
231+
options,
232+
timeStyle: null,
233+
dateStyle: dateStyle,
234+
withEra: withEra,
235+
);
227236

228237
@override
229-
FormatterImpl ymd({DateFormatStyle? dateStyle}) => FormatterECMA(
230-
this,
231-
DateTimeJSOptions(
232-
year: _timeStyle(null, dateStyle),
233-
month: _timeStyle(null, dateStyle),
234-
day: _timeStyle(null, dateStyle),
235-
),
236-
locale,
237-
options,
238-
timeStyle: null,
239-
dateStyle: dateStyle,
240-
);
238+
FormatterImpl ymd({DateFormatStyle? dateStyle, bool withEra = false}) =>
239+
FormatterECMA(
240+
this,
241+
DateTimeJSOptions(
242+
year: _timeStyle(null, dateStyle),
243+
month: _timeStyle(null, dateStyle),
244+
day: _timeStyle(null, dateStyle),
245+
),
246+
locale,
247+
options,
248+
timeStyle: null,
249+
dateStyle: dateStyle,
250+
withEra: withEra,
251+
);
241252

242253
@override
243-
FormatterImpl ymde({DateFormatStyle? dateStyle}) => FormatterECMA(
244-
this,
245-
DateTimeJSOptions(),
246-
locale,
247-
options,
248-
timeStyle: null,
249-
dateStyle: dateStyle,
250-
);
254+
FormatterImpl ymde({DateFormatStyle? dateStyle, bool withEra = false}) =>
255+
FormatterECMA(
256+
this,
257+
DateTimeJSOptions(),
258+
locale,
259+
options,
260+
timeStyle: null,
261+
dateStyle: dateStyle,
262+
withEra: withEra,
263+
);
251264

252265
@override
253266
FormatterImpl ymdet({
254267
DateFormatStyle? dateStyle,
255268
TimeFormatStyle? timeStyle,
269+
bool withEra = false,
256270
}) => FormatterECMA(
257271
this,
258272
DateTimeJSOptions(
@@ -267,6 +281,7 @@ class _DateTimeFormatECMA extends DateTimeFormatImpl {
267281
options,
268282
timeStyle: timeStyle,
269283
dateStyle: dateStyle,
284+
withEra: withEra,
270285
);
271286

272287
@override
@@ -283,12 +298,14 @@ class _DateTimeFormatECMA extends DateTimeFormatImpl {
283298
options,
284299
timeStyle: timeStyle,
285300
dateStyle: dateStyle,
301+
withEra: false,
286302
);
287303

288304
@override
289305
FormatterImpl ymdt({
290306
DateFormatStyle? dateStyle,
291307
TimeFormatStyle? timeStyle,
308+
bool withEra = false,
292309
}) => FormatterECMA(
293310
this,
294311
DateTimeJSOptions(
@@ -302,6 +319,7 @@ class _DateTimeFormatECMA extends DateTimeFormatImpl {
302319
options,
303320
timeStyle: timeStyle,
304321
dateStyle: dateStyle,
322+
withEra: withEra,
305323
);
306324

307325
static List<Locale> supportedLocalesOf(Locale locale) {
@@ -371,6 +389,7 @@ extension on DateTimeFormatOptions {
371389
DateTimeJSOptions options,
372390
TimeFormatStyle? timeStyle,
373391
DateFormatStyle? dateStyle,
392+
bool withEra,
374393
) => {
375394
if (dateStyle != null) 'dateStyle': dateStyle.name,
376395
if (timeStyle != null) 'timeStyle': timeStyle.name,
@@ -387,7 +406,7 @@ extension on DateTimeFormatOptions {
387406
},
388407
if (options.weekday != null && dateStyle == null)
389408
'weekday': options.weekday!.name,
390-
if (era != null && dateStyle == null) 'era': era!.name,
409+
if (withEra && dateStyle == null) 'era': Style.short.name,
391410
if (options.year != null && dateStyle == null) 'year': options.year!.jsName,
392411
if (options.month != null && dateStyle == null)
393412
'month': options.month!.jsName,

pkgs/intl4x/lib/src/datetime_format/datetime_format_impl.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,21 @@ abstract class DateTimeFormatImpl {
3131

3232
FormatterImpl d({DateFormatStyle? dateStyle});
3333
FormatterImpl m({DateFormatStyle? dateStyle});
34-
FormatterImpl y({DateFormatStyle? dateStyle});
34+
FormatterImpl y({DateFormatStyle? dateStyle, bool withEra});
3535
FormatterImpl md({DateFormatStyle? dateStyle});
36-
FormatterImpl ymd({DateFormatStyle? dateStyle});
37-
FormatterImpl ymde({DateFormatStyle? dateStyle});
36+
FormatterImpl ymd({DateFormatStyle? dateStyle, bool withEra});
37+
FormatterImpl ymde({DateFormatStyle? dateStyle, bool withEra});
3838
FormatterImpl mdt({DateFormatStyle? dateStyle, TimeFormatStyle? timeStyle});
39-
FormatterImpl ymdt({DateFormatStyle? dateStyle, TimeFormatStyle? timeStyle});
40-
FormatterImpl ymdet({DateFormatStyle? dateStyle, TimeFormatStyle? timeStyle});
39+
FormatterImpl ymdt({
40+
DateFormatStyle? dateStyle,
41+
TimeFormatStyle? timeStyle,
42+
bool withEra,
43+
});
44+
FormatterImpl ymdet({
45+
DateFormatStyle? dateStyle,
46+
TimeFormatStyle? timeStyle,
47+
bool withEra,
48+
});
4149
FormatterImpl t({TimeFormatStyle? style});
4250
}
4351

pkgs/intl4x/lib/src/datetime_format/datetime_format_options.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import '../options.dart';
66

77
typedef WeekDayStyle = Style;
88
typedef DayPeriod = Style;
9-
typedef EraStyle = Style;
109

1110
/// DateTime formatting functionality of the browser.
1211
class DateTimeFormatOptions {
@@ -19,7 +18,6 @@ class DateTimeFormatOptions {
1918

2019
/// Whether to use a 12- or 24-hour style clock.
2120
final ClockStyle? clockstyle;
22-
final EraStyle? era;
2321
final TimeStyle? timestyle;
2422

2523
/// The number of digits used to represent fractions of a second.
@@ -33,7 +31,6 @@ class DateTimeFormatOptions {
3331
this.dayPeriod,
3432
this.numberingSystem,
3533
this.clockstyle,
36-
this.era,
3734
this.timestyle,
3835
this.fractionalSecondDigits,
3936
this.formatMatcher = FormatMatcher.bestfit,
@@ -45,7 +42,6 @@ class DateTimeFormatOptions {
4542
NumberingSystem? numberingSystem,
4643
ClockStyle? clockstyle,
4744
WeekDayStyle? weekday,
48-
EraStyle? era,
4945
TimeStyle? timestyle,
5046
int? fractionalSecondDigits,
5147
FormatMatcher? formatMatcher,
@@ -55,7 +51,6 @@ class DateTimeFormatOptions {
5551
dayPeriod: dayPeriod ?? this.dayPeriod,
5652
numberingSystem: numberingSystem ?? this.numberingSystem,
5753
clockstyle: clockstyle ?? this.clockstyle,
58-
era: era ?? this.era,
5954
timestyle: timestyle ?? this.timestyle,
6055
fractionalSecondDigits:
6156
fractionalSecondDigits ?? this.fractionalSecondDigits,

0 commit comments

Comments
 (0)