Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: third_party/pkg/angular/lib/filter/date.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/filter/date.dart
diff --git a/third_party/pkg/angular/lib/filter/date.dart b/third_party/pkg/angular/lib/filter/date.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7d6be47029ce13c9fc079f676e1a3da804491546
--- /dev/null
+++ b/third_party/pkg/angular/lib/filter/date.dart
@@ -0,0 +1,65 @@
+part of angular.filter;
+
+/**
+ * Formats date to a string based on the requested format.
+ * See Dart http://api.dartlang.org/docs/releases/latest/intl/DateFormat.html
+ * for full formating options.
+ *
+ * - `medium`: equivalent to `MMM d, y h:mm:ss a` for en_US locale (e.g. Sep 3, 2010 12:05:08 pm)
+ * - `short`: equivalent to `M/d/yy h:mm a` for en_US locale (e.g. 9/3/10 12:05 pm)
+ * - `fullDate`: equivalent to `EEEE, MMMM d, y` for en_US locale (e.g. Friday, September 3, 2010)
+ * - `longDate`: equivalent to `MMMM d, y` for en_US locale (e.g. September 3, 2010)
+ * - `mediumDate`: equivalent to `MMM d, y` for en_US locale (e.g. Sep 3, 2010)
+ * - `shortDate`: equivalent to `M/d/yy` for en_US locale (e.g. 9/3/10)
+ * - `mediumTime`: equivalent to `h:mm:ss a` for en_US locale (e.g. 12:05:08 pm)
+ * - `shortTime`: equivalent to `h:mm a` for en_US locale (e.g. 12:05 pm)
+ *
+ *
+ * Usage:
+ *
+ * {{ date_expression | date[:format] }}
+ *
+ */
+@NgFilter(name:'date')
+class DateFilter {
+
+ static Map<String, String> MAP = {
+ 'medium': 'MMM d, y h:mm:ss a',
+ 'short': 'M/d/yy h:mm a',
+ 'fullDate': 'EEEE, MMMM d, y',
+ 'longDate': 'MMMM d, y',
+ 'mediumDate': 'MMM d, y',
+ 'shortDate': 'M/d/yy',
+ 'mediumTime': 'h:mm:ss a',
+ 'shortTime': 'h:mm a',
+ };
+
+ Map<num, NumberFormat> nfs = new Map<num, NumberFormat>();
+
+ /**
+ * [date]: Date to format either as Date object, milliseconds
+ * ([string] or [num]) or various ISO 8601 datetime string formats
+ * (e.g. `yyyy-MM-ddTHH:mm:ss.SSSZ` and its shorter versions like
+ * `yyyy-MM-ddTHH:mmZ`, `yyyy-MM-dd` or `yyyyMMddTHHmmssZ`). If no
+ * timezone is specified in the string input, the time is considered to
+ * be in the local timezone.
+ *
+ * [format]: Formatting rules (see Description). If not specified,
+ * mediumDate is used
+ *
+ */
+ call(date, [format = r'mediumDate']) {
+ if (date == '' || date == null) return date;
+ if (date is String) date = DateTime.parse(date);
+ if (date is num) date = new DateTime.fromMillisecondsSinceEpoch(date);
+ if (!(date is DateTime)) return date;
+ var nf = nfs[format];
+ if (nf == null) {
+ if (MAP.containsKey(format)) {
+ format = MAP[format];
+ }
+ nf = new DateFormat(format);
+ }
+ return nf.format(date);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698