Skip to content

Commit 51f7499

Browse files
committed
slight cleanup
1 parent 68d7982 commit 51f7499

File tree

1 file changed

+38
-48
lines changed

1 file changed

+38
-48
lines changed

executors/dart/lib/datetime_format.dart

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,21 @@ import 'package:intl4x/intl4x.dart';
1111
String testDateTimeFmt(String jsonEncoded) {
1212
final json = jsonDecode(jsonEncoded) as Map<String, dynamic>;
1313

14-
final label = json['label'];
1514
var localeString = json['locale'] as String?; // locale can be null from JSON
1615
if (localeString == null || localeString.isEmpty) {
1716
localeString = 'und'; // Default to 'und' if locale is null or empty
1817
}
1918

20-
final returnJson = <String, dynamic>{'label': label};
19+
final returnJson = <String, dynamic>{'label': json['label']};
2120

2221
// Parse Locale string
2322
Locale locale;
2423
try {
2524
locale = Locale.parse(localeString.replaceAll('_', '-'));
2625
} catch (e) {
27-
return jsonEncode({
28-
'label': label,
29-
'error': 'Invalid locale format: ${e.toString()}',
30-
'locale': localeString,
31-
});
26+
returnJson['error'] = 'Invalid locale format: ${e.toString()}';
27+
returnJson['locale'] = localeString;
28+
return jsonEncode(returnJson);
3229
}
3330

3431
var testOptionsJson = <String, dynamic>{};
@@ -92,11 +89,9 @@ String testDateTimeFmt(String jsonEncoded) {
9289
try {
9390
testDate = DateTime.parse(testDateString);
9491
} catch (e) {
95-
return jsonEncode({
96-
'label': label,
97-
'error': 'Invalid input_string date format: ${e.toString()}',
98-
'input_string': isoDateString,
99-
});
92+
returnJson['error'] = 'Invalid input_string date format: ${e.toString()}';
93+
returnJson['input_string'] = isoDateString;
94+
return jsonEncode(returnJson);
10095
}
10196
} else {
10297
testDate = DateTime.now();
@@ -128,6 +123,7 @@ String testDateTimeFmt(String jsonEncoded) {
128123
} on Exception catch (e) {
129124
returnJson['error_type'] = 'unsupported';
130125
returnJson['unsupported'] = ': ${e.toString()}';
126+
return jsonEncode(returnJson);
131127
}
132128
returnJson['actual_options'] = dateTimeFormatOptions.humanReadable;
133129
returnJson['options'] = testOptionsJson;
@@ -167,48 +163,42 @@ DateTimeFormatter getFormatterForSkeleton(
167163
ZonedDateTimeFormatter getZonedFormatter(
168164
String timeZoneStyle,
169165
DateTimeFormatter formatter,
170-
) {
171-
final zonedFormatter = switch (timeZoneStyle) {
172-
'short' => formatter.withTimeZoneShort(),
173-
'long' => formatter.withTimeZoneLong(),
174-
'full' => formatter.withTimeZoneLongGeneric(),
175-
String() => throw Exception('Unknown time zone style `$timeZoneStyle`'),
176-
};
177-
return zonedFormatter;
178-
}
166+
) => switch (timeZoneStyle) {
167+
'short' => formatter.withTimeZoneShort(),
168+
'long' => formatter.withTimeZoneLong(),
169+
'full' => formatter.withTimeZoneLongGeneric(),
170+
String() => throw Exception('Unknown time zone style `$timeZoneStyle`'),
171+
};
179172

180173
DateTimeFormatter getFormatterForStyle(
181174
String? dateStyle,
182175
String? timeStyle,
183176
String? yearStyle,
184177
DateTimeFormatBuilder dtFormatter,
185-
) {
186-
final formatter = switch ((dateStyle, timeStyle, yearStyle)) {
187-
('medium', null, _) => dtFormatter.ymd(dateStyle: DateFormatStyle.medium),
188-
(null, 'short', _) => dtFormatter.t(style: TimeFormatStyle.short),
189-
('full', 'short', null) => dtFormatter.ymdet(
190-
dateStyle: DateFormatStyle.full,
191-
timeStyle: TimeFormatStyle.short,
192-
),
193-
('full', 'full', null) => dtFormatter.ymdet(
194-
dateStyle: DateFormatStyle.full,
195-
timeStyle: TimeFormatStyle.full,
196-
),
197-
('short', 'full', null) => dtFormatter.ymdt(
198-
dateStyle: DateFormatStyle.short,
199-
timeStyle: TimeFormatStyle.full,
200-
),
201-
('short', 'full', 'with_era') => dtFormatter.ymdet(
202-
dateStyle: DateFormatStyle.short,
203-
timeStyle: TimeFormatStyle.full,
204-
),
205-
(_, _, 'with_era') => dtFormatter.ymde(),
206-
(_, _, _) => throw Exception(
207-
'Unknown combination of date style `$dateStyle`, time style `$timeStyle`, and year style `$yearStyle`',
208-
),
209-
};
210-
return formatter;
211-
}
178+
) => switch ((dateStyle, timeStyle, yearStyle)) {
179+
('medium', null, _) => dtFormatter.ymd(dateStyle: DateFormatStyle.medium),
180+
(null, 'short', _) => dtFormatter.t(style: TimeFormatStyle.short),
181+
('full', 'short', null) => dtFormatter.ymdet(
182+
dateStyle: DateFormatStyle.full,
183+
timeStyle: TimeFormatStyle.short,
184+
),
185+
('full', 'full', null) => dtFormatter.ymdet(
186+
dateStyle: DateFormatStyle.full,
187+
timeStyle: TimeFormatStyle.full,
188+
),
189+
('short', 'full', null) => dtFormatter.ymdt(
190+
dateStyle: DateFormatStyle.short,
191+
timeStyle: TimeFormatStyle.full,
192+
),
193+
('short', 'full', 'with_era') => dtFormatter.ymdet(
194+
dateStyle: DateFormatStyle.short,
195+
timeStyle: TimeFormatStyle.full,
196+
),
197+
(_, _, 'with_era') => dtFormatter.ymde(),
198+
(_, _, _) => throw Exception(
199+
'Unknown combination of date style `$dateStyle`, time style `$timeStyle`, and year style `$yearStyle`',
200+
),
201+
};
212202

213203
extension on DateTimeFormatOptions {
214204
String get humanReadable {

0 commit comments

Comments
 (0)