@abp/core 9.1.1 → 9.2.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/abp.js +67 -28
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "9.1.1",
2
+ "version": "9.2.0-rc.2",
3
3
  "name": "@abp/core",
4
4
  "repository": {
5
5
  "type": "git",
@@ -10,7 +10,7 @@
10
10
  "access": "public"
11
11
  },
12
12
  "dependencies": {
13
- "@abp/utils": "~9.1.1"
13
+ "@abp/utils": "~9.2.0-rc.2"
14
14
  },
15
15
  "gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431",
16
16
  "homepage": "https://abp.io",
package/src/abp.js CHANGED
@@ -81,7 +81,7 @@ var abp = abp || {};
81
81
  if (resource) {
82
82
  return resource;
83
83
  }
84
-
84
+
85
85
  var legacySource = abp.localization.values[resourceName];
86
86
  if (legacySource) {
87
87
  return {
@@ -89,11 +89,11 @@ var abp = abp || {};
89
89
  baseResources: []
90
90
  };
91
91
  }
92
-
93
- abp.log.warn('Could not find localization source: ' + resourceName);
92
+
93
+ abp.log.warn('Could not find localization source: ' + resourceName);
94
94
  return null;
95
95
  };
96
-
96
+
97
97
  abp.localization.internal.localize = function (key, sourceName) {
98
98
  var resource = abp.localization.internal.getResource(sourceName);
99
99
  if (!resource){
@@ -104,7 +104,7 @@ var abp = abp || {};
104
104
  }
105
105
 
106
106
  var value = resource.texts[key];
107
- if (value === undefined) {
107
+ if (value === undefined) {
108
108
  for (var i = 0; i < resource.baseResources.length; i++){
109
109
  var basedArguments = Array.prototype.slice.call(arguments, 0);
110
110
  basedArguments[1] = resource.baseResources[i];
@@ -114,7 +114,7 @@ var abp = abp || {};
114
114
  return result;
115
115
  }
116
116
  }
117
-
117
+
118
118
  return {
119
119
  value: key,
120
120
  found: false
@@ -135,7 +135,7 @@ var abp = abp || {};
135
135
  if (sourceName === '_') { //A convention to suppress the localization
136
136
  return key;
137
137
  }
138
-
138
+
139
139
  if (sourceName) {
140
140
  return abp.localization.internal.localize.apply(this, arguments).value;
141
141
  }
@@ -750,7 +750,11 @@ var abp = abp || {};
750
750
 
751
751
  abp.clock.supportsMultipleTimezone = function () {
752
752
  return abp.clock.kind === 'Utc';
753
- };
753
+ }
754
+
755
+ abp.clock.timeZone = function () {
756
+ return abp.setting.get('Abp.Timing.TimeZone') || abp.clock.browserTimeZone();
757
+ }
754
758
 
755
759
  // Normalize Date object or date string to standard string format that will be sent to server
756
760
  abp.clock.normalizeToString = function (date) {
@@ -763,32 +767,42 @@ var abp = abp || {};
763
767
  return date;
764
768
  }
765
769
 
766
- if (abp.clock.kind === 'Utc') {
767
- return dateObj.toISOString();
768
- }
769
-
770
770
  function padZero(num) {
771
771
  return num < 10 ? '0' + num : num;
772
772
  }
773
773
 
774
- function padMilliseconds(num) {
775
- if (num < 10) return '00' + num;
776
- if (num < 100) return '0' + num;
777
- return num;
774
+ var addZulu = false;
775
+ if (abp.clock.supportsMultipleTimezone()) {
776
+ var timeZone = abp.clock.timeZone();
777
+ var now = new Date();
778
+ var formattedDate = now.toLocaleString('en-US', { timeZone: timeZone, timeZoneName: 'longOffset' });
779
+ var match = formattedDate.match(/GMT([+-]\d+)/);
780
+ var targetOffsetHours = match ? parseInt(match[1], 10) : 0;
781
+ var dateObj = new Date(dateObj.getTime() - (targetOffsetHours * 60 * 60 * 1000));
782
+ addZulu = true;
778
783
  }
779
-
780
- // yyyy-MM-ddTHH:mm:ss.SSS
784
+
785
+ // yyyy-MM-DDTHH:mm:ss
781
786
  return dateObj.getFullYear() + '-' +
782
- padZero(dateObj.getMonth() + 1) + '-' +
783
- padZero(dateObj.getDate()) + 'T' +
784
- padZero(dateObj.getHours()) + ':' +
785
- padZero(dateObj.getMinutes()) + ':' +
786
- padZero(dateObj.getSeconds()) + '.' +
787
- padMilliseconds(dateObj.getMilliseconds());
787
+ padZero(dateObj.getMonth() + 1) + '-' +
788
+ padZero(dateObj.getDate()) + 'T' +
789
+ padZero(dateObj.getHours()) + ':' +
790
+ padZero(dateObj.getMinutes()) + ':' +
791
+ padZero(dateObj.getSeconds()) + (addZulu ? 'Z' : '');
792
+ };
793
+
794
+ // Default options for toLocaleString
795
+ abp.clock.toLocaleStringOptions = abp.clock.toLocaleStringOptions || {
796
+ "year": "numeric",
797
+ "month": "long",
798
+ "day": "numeric",
799
+ "hour": "numeric",
800
+ "minute": "numeric",
801
+ "second": "numeric"
788
802
  };
789
803
 
790
804
  // Normalize date string to locale date string that will be displayed to user
791
- abp.clock.normalizeToLocaleString = function (dateString) {
805
+ abp.clock.normalizeToLocaleString = function (dateString, options) {
792
806
  if (!dateString) {
793
807
  return dateString;
794
808
  }
@@ -797,11 +811,36 @@ var abp = abp || {};
797
811
  if (isNaN(date)) {
798
812
  return dateString;
799
813
  }
800
-
801
- //TODO: Get timezone setting and pass it to toLocaleString
802
- return date.toLocaleString();
814
+
815
+ var culture = abp.localization.currentCulture.cultureName;
816
+ options = options || abp.clock.toLocaleStringOptions;
817
+ if (abp.clock.supportsMultipleTimezone()) {
818
+ var timezone = abp.clock.timeZone();
819
+ if (timezone) {
820
+ return date.toLocaleString(culture, Object.assign({}, options, { timeZone: timezone }));
821
+ }
822
+ }
823
+ return date.toLocaleString(culture, options);
803
824
  }
804
825
 
826
+ abp.clock.browserTimeZone = function () {
827
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
828
+ }
829
+
830
+ abp.clock.trySetBrowserTimeZoneToCookie = true;
831
+
832
+ abp.clock.setBrowserTimeZoneToCookie = function () {
833
+ if (!abp.clock.trySetBrowserTimeZoneToCookie || !abp.clock.supportsMultipleTimezone() || abp.currentUser.isAuthenticated) {
834
+ return;
835
+ }
836
+
837
+ abp.utils.setCookieValue('__timezone', abp.clock.browserTimeZone(), new Date(new Date().setFullYear(new Date().getFullYear() + 1)), '/');
838
+ }
839
+
840
+ abp.event.on('abp.configurationInitialized', function () {
841
+ abp.clock.setBrowserTimeZoneToCookie();
842
+ });
843
+
805
844
  /* FEATURES *************************************************/
806
845
 
807
846
  abp.features = abp.features || {};