diff options
Diffstat (limited to 'src/ng')
| -rw-r--r-- | src/ng/filter/filters.js | 24 | 
1 files changed, 23 insertions, 1 deletions
diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js index 078c54fc..c792cace 100644 --- a/src/ng/filter/filters.js +++ b/src/ng/filter/filters.js @@ -288,7 +288,8 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+   *   (e.g. `"h o''clock"`).   *   * @param {(Date|number|string)} date Date to format either as Date object, milliseconds (string or - *    number) or ISO 8601 extended datetime string (yyyy-MM-ddTHH:mm:ss.SSSZ). + *    number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.SSSZ and it's + *    shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ).   * @param {string=} format Formatting rules (see Description). If not specified,   *    `mediumDate` is used.   * @returns {string} Formatted string or the input if input is not recognized as date/millis. @@ -317,6 +318,27 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+   */  dateFilter.$inject = ['$locale'];  function dateFilter($locale) { + + +  var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/; +  function jsonStringToDate(string){ +    var match; +    if (match = string.match(R_ISO8601_STR)) { +      var date = new Date(0), +          tzHour = 0, +          tzMin  = 0; +      if (match[9]) { +        tzHour = int(match[9] + match[10]); +        tzMin = int(match[9] + match[11]); +      } +      date.setUTCFullYear(int(match[1]), int(match[2]) - 1, int(match[3])); +      date.setUTCHours(int(match[4]||0) - tzHour, int(match[5]||0) - tzMin, int(match[6]||0), int(match[7]||0)); +      return date; +    } +    return string; +  } + +    return function(date, format) {      var text = '',          parts = [],  | 
