Skip to content

Commit dbaded5

Browse files
authored
Merge pull request #39 from iLib-js/ilibdateoptions_utc
Fix incorrect timezone handling when DateTime is UTC
2 parents 8f61666 + 8d9beca commit dbaded5

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.2.1
2+
* Fixed incorrect timezone handling when [DateTime](https://api.flutter.dev/flutter/dart-core/DateTime-class.html) where UTC-based times were being misinterpreted as local time during formatting and parsing.
3+
14
## 1.2.0
25
* Added `isILibReady` getter to `ILibJS` class to expose internal `_iLibPrepared` state.
36
* Added `isILibReady` getter to `FlutterILib` class for external access to ILibJS initialization status.

lib/ilib_datefmt.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ class ILibDateOptions {
205205

206206
final Map<String, String> paramInfo = <String, String>{
207207
'locale': '$locale',
208-
'timezone': '$timezone',
208+
// If dateTime is not null and is in UTC, set timezone to 'Etc/UTC'.
209+
// Otherwise, use the provided timezone value.
210+
'timezone': (dateTime?.isUtc ?? false) ? 'Etc/UTC' : '$timezone',
209211
'type': '$type',
210212
'calendar': '$calendar'
211213
};

pubspec.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ packages:
131131
url: "https://pub.dev"
132132
source: hosted
133133
version: "4.0.0"
134+
logging:
135+
dependency: "direct main"
136+
description:
137+
name: logging
138+
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
139+
url: "https://pub.dev"
140+
source: hosted
141+
version: "1.3.0"
134142
matcher:
135143
dependency: transitive
136144
description:

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_ilib
22
description: "A wrapper plugin to conveniently use 'iLib' in Flutter app for internationalization. This plugin uses the 'flutter_js' to make the JavaScript file work properly in the Flutter app."
3-
version: 1.2.0
3+
version: 1.2.1
44
homepage: https://github.com/iLib-js/flutter_ilib
55
repository: https://github.com/iLib-js/flutter_ilib
66

test/basic/flutter_ilib_datefmt_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ void main() {
7373
ILibDateOptions(dateTime: DateTime.parse('2024-06-27 10:42'));
7474
expect(fmt.format(dateOptions), '2024년 6월 27일 오전 10:42');
7575
});
76+
test('ILibDateFmt_DateTimeObj_utc_koKR', () {
77+
final ILibDateFmtOptions fmtOptions = ILibDateFmtOptions(
78+
locale: 'ko-KR', length: 'full', type: 'datetime', useNative: false);
79+
final ILibDateFmt fmt = ILibDateFmt(fmtOptions);
80+
final ILibDateOptions dateOptions =
81+
ILibDateOptions(dateTime: DateTime.parse('2024-06-27 10:42Z'));
82+
expect(fmt.format(dateOptions), '2024년 6월 27일 오후 7:42');
83+
});
84+
test('ILibDateFmt_DateTimeObj_utc_enUS', () {
85+
final ILibDateFmtOptions fmtOptions = ILibDateFmtOptions(
86+
locale: 'en-US', length: 'full', type: 'datetime', useNative: false);
87+
final ILibDateFmt fmt = ILibDateFmt(fmtOptions);
88+
final ILibDateOptions dateOptions =
89+
ILibDateOptions(dateTime: DateTime.utc(2024, 6, 27, 10, 42));
90+
expect(fmt.format(dateOptions), 'June 27, 2024 at 6:42 AM');
91+
});
7692
});
7793
group('getClock()', () {
7894
test('getClock_ko_KR', () {

0 commit comments

Comments
 (0)