Skip to content

Commit 2458805

Browse files
authored
Merge pull request #95 from juliano-souza000/fix/non_en_us_date_time_parse
Fix non en-US date time parse
2 parents dc821b8 + dc82296 commit 2458805

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/src/utils.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ String trimDoubleQuote(String str) {
122122
}
123123

124124
DateTime parseRfc7231Time(String time) {
125-
final format = DateFormat('EEE, dd MMM yyyy HH:mm:ss');
125+
final format = DateFormat('EEE, dd MMM yyyy HH:mm:ss', 'en-US');
126126
final isUtc = time.endsWith('GMT');
127127
return format.parse(time, isUtc);
128128
}
129129

130130
String toRfc7231Time(DateTime time) {
131-
final format = DateFormat('EEE, dd MMM yyyy HH:mm:ss');
131+
final format = DateFormat('EEE, dd MMM yyyy HH:mm:ss', 'en-US');
132132
final result = format.format(time);
133133
return time.isUtc ? '$result GMT' : result;
134134
}

test/utils_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'dart:typed_data';
22

3+
import 'package:intl/date_symbol_data_local.dart';
4+
import 'package:intl/intl.dart';
35
import 'package:minio/src/utils.dart';
46
import 'package:test/test.dart';
57

@@ -25,6 +27,20 @@ void testRfc7231Time() {
2527
expect(parseRfc7231Time(timeStringUtc), equals(timeUtc));
2628
expect(parseRfc7231Time(timeStringUtc).isUtc, isTrue);
2729
});
30+
31+
test(
32+
'works for non en-US locale', () async {
33+
initializeDateFormatting('pt_BR');
34+
Intl.withLocale(
35+
'pt_BR',
36+
()
37+
{
38+
expect(parseRfc7231Time(timeStringUtc), equals(timeUtc));
39+
expect(parseRfc7231Time(timeStringUtc).isUtc, isTrue);
40+
}
41+
);
42+
}
43+
);
2844
});
2945

3046
group('toRfc7231Time', () {
@@ -35,6 +51,19 @@ void testRfc7231Time() {
3551
test('works for GMT time', () {
3652
expect(toRfc7231Time(timeUtc), equals(timeStringUtc));
3753
});
54+
55+
test(
56+
'works for non en-US locale', () async {
57+
initializeDateFormatting('pt_BR');
58+
Intl.withLocale(
59+
'pt_BR',
60+
()
61+
{
62+
expect(toRfc7231Time(timeUtc), equals(timeStringUtc));
63+
}
64+
);
65+
}
66+
);
3867
});
3968
}
4069

0 commit comments

Comments
 (0)