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

Commit

Permalink
fix(DateFilter): cache DateFormat correctly
Browse files Browse the repository at this point in the history
- cache named date formats (such as 'medium', 'short' and so on...)
- cache DateFormat for each locales

Closes #882
  • Loading branch information
technohippy authored and [email protected] committed Apr 11, 2014
1 parent 356df76 commit 64cf96f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/filter/date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Date implements Function {
'shortTime': 'h:mm a',
};

var _dfs = <String, DateFormat>{};
var _dfs = new Map<String, Map<String, DateFormat>>();

/**
* [date]: Date to format either as Date object, milliseconds
Expand All @@ -52,13 +52,13 @@ class Date implements Function {
if (date is String) date = DateTime.parse(date);
if (date is num) date = new DateTime.fromMillisecondsSinceEpoch(date);
if (date is! DateTime) return date;
var df = _dfs[format];
if (_MAP.containsKey(format)) format = _MAP[format];
var verifiedLocale = Intl.verifiedLocale(Intl.getCurrentLocale(), DateFormat.localeExists);
_dfs.putIfAbsent(verifiedLocale, () => new Map<String, DateFormat>());
var df = _dfs[verifiedLocale][format];
if (df == null) {
if (_MAP.containsKey(format)) {
format = _MAP[format];
}
df = new DateFormat(format);
_dfs[format] = df;
_dfs[verifiedLocale][format] = df;
}
return df.format(date);
}
Expand Down

0 comments on commit 64cf96f

Please sign in to comment.