Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 9034238

Browse files
technohippymhevery
authored andcommitted
fix(DateFilter): cache DateFormat correctly
- cache named date formats (such as 'medium', 'short' and so on...) - cache DateFormat for each locales Closes #882
1 parent c73a0c7 commit 9034238

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/filter/date.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Date implements Function {
3333
'shortTime': 'h:mm a',
3434
};
3535

36-
var _dfs = <String, DateFormat>{};
36+
var _dfs = new Map<String, Map<String, DateFormat>>();
3737

3838
/**
3939
* [date]: Date to format either as Date object, milliseconds
@@ -52,13 +52,13 @@ class Date implements Function {
5252
if (date is String) date = DateTime.parse(date);
5353
if (date is num) date = new DateTime.fromMillisecondsSinceEpoch(date);
5454
if (date is! DateTime) return date;
55-
var df = _dfs[format];
55+
if (_MAP.containsKey(format)) format = _MAP[format];
56+
var verifiedLocale = Intl.verifiedLocale(Intl.getCurrentLocale(), DateFormat.localeExists);
57+
_dfs.putIfAbsent(verifiedLocale, () => new Map<String, DateFormat>());
58+
var df = _dfs[verifiedLocale][format];
5659
if (df == null) {
57-
if (_MAP.containsKey(format)) {
58-
format = _MAP[format];
59-
}
6060
df = new DateFormat(format);
61-
_dfs[format] = df;
61+
_dfs[verifiedLocale][format] = df;
6262
}
6363
return df.format(date);
6464
}

0 commit comments

Comments
 (0)