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

Commit cec3eda

Browse files
technohippymhevery
authored andcommitted
fix(DateFilter): fix a wrong type
Closes #579
1 parent cf0160b commit cec3eda

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

lib/filter/date.dart

+11-10
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ part of angular.filter;
2121
*
2222
*/
2323
@NgFilter(name:'date')
24-
class DateFilter {
25-
static Map<String, String> MAP = {
24+
class DateFilter implements Function {
25+
static final _MAP = const <String, String> {
2626
'medium': 'MMM d, y h:mm:ss a',
2727
'short': 'M/d/yy h:mm a',
2828
'fullDate': 'EEEE, MMMM d, y',
@@ -33,7 +33,7 @@ class DateFilter {
3333
'shortTime': 'h:mm a',
3434
};
3535

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

3838
/**
3939
* [date]: Date to format either as Date object, milliseconds
@@ -47,18 +47,19 @@ class DateFilter {
4747
* mediumDate is used
4848
*
4949
*/
50-
call(date, [format = r'mediumDate']) {
50+
dynamic call(Object date, [String format = 'mediumDate']) {
5151
if (date == '' || date == null) return date;
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 nf = nfs[format];
56-
if (nf == null) {
57-
if (MAP.containsKey(format)) {
58-
format = MAP[format];
55+
var df = _dfs[format];
56+
if (df == null) {
57+
if (_MAP.containsKey(format)) {
58+
format = _MAP[format];
5959
}
60-
nf = new DateFormat(format);
60+
df = new DateFormat(format);
61+
_dfs[format] = df;
6162
}
62-
return nf.format(date);
63+
return df.format(date);
6364
}
6465
}

test/filter/date_spec.dart

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ library date_spec;
33
import '../_specs.dart';
44

55
main() => describe('date', () {
6-
var morning = DateTime.parse('2010-09-03T07:05:08.008Z'); //7am
7-
var noon = DateTime.parse('2010-09-03T12:05:08.012Z'); //12pm
8-
var midnight = DateTime.parse('2010-09-03T12:05:08.123Z'); //12am
6+
var morning = DateTime.parse('2010-09-03T07:05:08.008Z'); //7am
7+
var noon = DateTime.parse('2010-09-03T12:05:08.012Z'); //12pm
8+
var midnight = DateTime.parse('2010-09-03T12:05:08.123Z'); //12am
99
var earlyDate = DateTime.parse('0001-09-03T05:05:08.000Z');
1010

1111
var date;
@@ -57,4 +57,10 @@ main() => describe('date', () {
5757
expect(date(noon, "shortTime")).
5858
toEqual('12:05 PM');
5959
});
60+
61+
it('should use cache without any error', () {
62+
63+
date(noon, "shortTime");
64+
date(noon, "shortTime");
65+
});
6066
});

0 commit comments

Comments
 (0)