@abp/core 9.0.4 → 9.0.6

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 +40 -37
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "9.0.4",
2
+ "version": "9.0.6",
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.0.4"
13
+ "@abp/utils": "~9.0.6"
14
14
  },
15
15
  "gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431",
16
16
  "homepage": "https://abp.io",
package/src/abp.js CHANGED
@@ -752,53 +752,56 @@ var abp = abp || {};
752
752
  return abp.clock.kind === 'Utc';
753
753
  };
754
754
 
755
- var toLocal = function (date) {
756
- return new Date(
757
- date.getFullYear(),
758
- date.getMonth(),
759
- date.getDate(),
760
- date.getHours(),
761
- date.getMinutes(),
762
- date.getSeconds(),
763
- date.getMilliseconds()
764
- );
765
- };
766
-
767
- var toUtc = function (date) {
768
- return Date.UTC(
769
- date.getUTCFullYear(),
770
- date.getUTCMonth(),
771
- date.getUTCDate(),
772
- date.getUTCHours(),
773
- date.getUTCMinutes(),
774
- date.getUTCSeconds(),
775
- date.getUTCMilliseconds()
776
- );
777
- };
778
-
779
- abp.clock.now = function () {
780
- if (abp.clock.kind === 'Utc') {
781
- return toUtc(new Date());
755
+ // Normalize Date object or date string to standard string format that will be sent to server
756
+ abp.clock.normalizeToString = function (date) {
757
+ if (!date) {
758
+ return date;
782
759
  }
783
- return new Date();
784
- };
785
-
786
- abp.clock.normalize = function (date) {
787
- var kind = abp.clock.kind;
788
760
 
789
- if (kind === 'Unspecified') {
761
+ var dateObj = date instanceof Date ? date : new Date(date);
762
+ if (isNaN(dateObj)) {
790
763
  return date;
791
764
  }
792
765
 
793
- if (kind === 'Local') {
794
- return toLocal(date);
766
+ if (abp.clock.kind === 'Utc') {
767
+ return dateObj.toISOString();
768
+ }
769
+
770
+ function padZero(num) {
771
+ return num < 10 ? '0' + num : num;
795
772
  }
796
773
 
797
- if (kind === 'Utc') {
798
- return toUtc(date);
774
+ function padMilliseconds(num) {
775
+ if (num < 10) return '00' + num;
776
+ if (num < 100) return '0' + num;
777
+ return num;
799
778
  }
779
+
780
+ // yyyy-MM-ddTHH:mm:ss.SSS
781
+ 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());
800
788
  };
801
789
 
790
+ // Normalize date string to locale date string that will be displayed to user
791
+ abp.clock.normalizeToLocaleString = function (dateString) {
792
+ if (!dateString) {
793
+ return dateString;
794
+ }
795
+
796
+ var date = new Date(dateString);
797
+ if (isNaN(date)) {
798
+ return dateString;
799
+ }
800
+
801
+ //TODO: Get timezone setting and pass it to toLocaleString
802
+ return date.toLocaleString();
803
+ }
804
+
802
805
  /* FEATURES *************************************************/
803
806
 
804
807
  abp.features = abp.features || {};