فهرست منبع

smarter about short tzo injection in IE11

Adam Shaw 7 سال پیش
والد
کامیت
f56e7cdaa3
1فایلهای تغییر یافته به همراه19 افزوده شده و 3 حذف شده
  1. 19 3
      src/datelib/formatting-native.ts

+ 19 - 3
src/datelib/formatting-native.ts

@@ -208,9 +208,9 @@ function postProcess(s: string, date: ZonedMarker, standardDateProps, extendedSe
 
 
   s = s.replace(LTR_RE, '') // remove left-to-right control chars. do first. good for other regexes
   s = s.replace(LTR_RE, '') // remove left-to-right control chars. do first. good for other regexes
 
 
-  if (standardDateProps.timeZoneName) {
-    s = s.replace(
-      UTC_RE,
+  if (standardDateProps.timeZoneName === 'short') {
+    s = injectTzoStr(
+      s,
       (context.timeZone === 'UTC' || date.timeZoneOffset == null) ?
       (context.timeZone === 'UTC' || date.timeZoneOffset == null) ?
         'UTC' : // important to normalize for IE, which does "GMT"
         'UTC' : // important to normalize for IE, which does "GMT"
         formatTimeZoneOffset(date.timeZoneOffset)
         formatTimeZoneOffset(date.timeZoneOffset)
@@ -246,6 +246,22 @@ function postProcess(s: string, date: ZonedMarker, standardDateProps, extendedSe
   return s
   return s
 }
 }
 
 
+function injectTzoStr(s: string, tzoStr: string): string {
+  let replaced = false
+
+  s = s.replace(UTC_RE, function() {
+    replaced = true
+    return tzoStr
+  })
+
+  // IE11 doesn't include UTC/GMT in the original string, so append to end
+  if (!replaced) {
+    s = s + ' ' + tzoStr
+  }
+
+  return s
+}
+
 function formatWeekNumber(num: number, weekLabel: string, locale: Locale, display?: 'numeric' | 'narrow' | 'short'): string {
 function formatWeekNumber(num: number, weekLabel: string, locale: Locale, display?: 'numeric' | 'narrow' | 'short'): string {
   let parts = []
   let parts = []