Skip to content

Commit

Permalink
Merge pull request #95 from juliano-souza000/fix/non_en_us_date_time_…
Browse files Browse the repository at this point in the history
…parse

Fix non en-US date time parse
  • Loading branch information
lijy91 authored Nov 3, 2024
2 parents dc821b8 + dc82296 commit 2458805
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ String trimDoubleQuote(String str) {
}

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

String toRfc7231Time(DateTime time) {
final format = DateFormat('EEE, dd MMM yyyy HH:mm:ss');
final format = DateFormat('EEE, dd MMM yyyy HH:mm:ss', 'en-US');
final result = format.format(time);
return time.isUtc ? '$result GMT' : result;
}
Expand Down
29 changes: 29 additions & 0 deletions test/utils_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:typed_data';

import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:minio/src/utils.dart';
import 'package:test/test.dart';

Expand All @@ -25,6 +27,20 @@ void testRfc7231Time() {
expect(parseRfc7231Time(timeStringUtc), equals(timeUtc));
expect(parseRfc7231Time(timeStringUtc).isUtc, isTrue);
});

test(
'works for non en-US locale', () async {
initializeDateFormatting('pt_BR');
Intl.withLocale(
'pt_BR',
()
{
expect(parseRfc7231Time(timeStringUtc), equals(timeUtc));
expect(parseRfc7231Time(timeStringUtc).isUtc, isTrue);
}
);
}
);
});

group('toRfc7231Time', () {
Expand All @@ -35,6 +51,19 @@ void testRfc7231Time() {
test('works for GMT time', () {
expect(toRfc7231Time(timeUtc), equals(timeStringUtc));
});

test(
'works for non en-US locale', () async {
initializeDateFormatting('pt_BR');
Intl.withLocale(
'pt_BR',
()
{
expect(toRfc7231Time(timeUtc), equals(timeStringUtc));
}
);
}
);
});
}

Expand Down

0 comments on commit 2458805

Please sign in to comment.