@js-joda/core 5.6.5 → 6.0.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@js-joda/core",
3
- "version": "5.6.5",
3
+ "version": "6.0.0",
4
4
  "description": "a date and time library for javascript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,7 +31,6 @@
31
31
  "test": "NODE_ENV=test npx mocha --timeout 5000 --require @babel/register ./test/*Test_mochaOnly.js ./test/*Test.js ./test/**/*Test.js ./test/**/**/*Test.js",
32
32
  "test-coverage": "NODE_ENV=test COVERAGE=1 npx nyc --report-dir=build/coverage --reporter=lcov --reporter html npx mocha --timeout 5000 --require @babel/register --reporter progress ./test/*Test.js ./test/**/*Test.js ./test/**/**/*Test.js",
33
33
  "test-browser": "npx karma start --reporters=dots --single-run",
34
- "test-saucelabs": "npx karma start --reporters=\"dots,saucelabs\" --browsers=\"sl_chrome,sl_firefox\" --single-run=true",
35
34
  "test-ci": "npm run build-dist && npm run test && npm run test-browser && npm run test-ts-definitions && npm run test-coverage",
36
35
  "test-ts-definitions": "TS_NODE_PROJECT='../../shared/ts-test-config.json' NODE_ENV=test mocha --timeout 5000 --require ts-node/register ./test/typescript_definitions/*.ts",
37
36
  "build-dist": "npx rollup -c rollup.config.js",
@@ -48,5 +47,5 @@
48
47
  "sourceMap": false,
49
48
  "instrument": false
50
49
  },
51
- "gitHead": "0e0db1449c1ac7eb1d38ba0852fa11e3ae598e48"
50
+ "gitHead": "70d32a399ecba3424fdfb665bafc6247d918083f"
52
51
  }
package/src/Duration.js CHANGED
@@ -1080,6 +1080,69 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
1080
1080
  return totalNanos;
1081
1081
  }
1082
1082
 
1083
+ //-----------------------------------------------------------------------
1084
+ /**
1085
+ * Extracts the number of hours part in the duration.
1086
+ *
1087
+ * This returns the number of remaining hours when dividing {@link Duration.toHours}
1088
+ * by hours in a day.
1089
+ * This is based on the standard definition of a day as 24 hours.
1090
+ *
1091
+ * This instance is immutable and unaffected by this method call.
1092
+ *
1093
+ * @return {number} the number of hours part in the duration, may be negative
1094
+ */
1095
+ toHoursPart() {
1096
+ return MathUtil.intMod(this.toHours(), LocalTime.HOURS_PER_DAY);
1097
+ }
1098
+
1099
+ /**
1100
+ * Extracts the number of minutes part in the duration.
1101
+ *
1102
+ * This returns the number of remaining minutes when dividing {@link Duration.toMinutes}
1103
+ * by minutes in an hour.
1104
+ * This is based on the standard definition of an hour as 60 minutes.
1105
+ *
1106
+ * This instance is immutable and unaffected by this method call.
1107
+ *
1108
+ * @return {number} the number of minutes parts in the duration, may be negative
1109
+ */
1110
+ toMinutesPart() {
1111
+ return MathUtil.intMod(this.toMinutes(), LocalTime.MINUTES_PER_HOUR);
1112
+ }
1113
+
1114
+ /**
1115
+ * Extracts the number of seconds part in the duration.
1116
+ *
1117
+ * This returns the remaining seconds when dividing {@link Duration.toSeconds}
1118
+ * by seconds in a minute.
1119
+ * This is based on the standard definition of a minute as 60 seconds.
1120
+ *
1121
+ * This instance is immutable and unaffected by this method call.
1122
+ *
1123
+ * @return {number} the number of seconds parts in the duration, may be negative
1124
+ */
1125
+ toSecondsPart() {
1126
+ return MathUtil.intMod(this._seconds, LocalTime.SECONDS_PER_MINUTE);
1127
+ }
1128
+
1129
+ /**
1130
+ * Extracts the number of milliseconds part of the duration.
1131
+ *
1132
+ * This returns the milliseconds part by dividing the number of nanoseconds by 1,000,000.
1133
+ * The length of the duration is stored using two fields - seconds and nanoseconds.
1134
+ * The nanoseconds part is a value from 0 to 999,999,999 that is an adjustment to
1135
+ * the length in seconds.
1136
+ * The total duration is defined by calling {@link Duration.nano} and {@link Duration.seconds}.
1137
+ *
1138
+ * This instance is immutable and unaffected by this method call.
1139
+ *
1140
+ * @return {number} the number of milliseconds part of the duration.
1141
+ */
1142
+ toMillisPart() {
1143
+ return MathUtil.intDiv(this._nanos, 1000000);
1144
+ }
1145
+
1083
1146
  //-----------------------------------------------------------------------
1084
1147
  /**
1085
1148
  * Compares this duration to the specified {@link Duration}.
package/src/MathUtil.js CHANGED
@@ -168,11 +168,7 @@ export class MathUtil {
168
168
  if (isNaN(value)) {
169
169
  throw new ArithmeticException('Invalid int value, using NaN as argument');
170
170
  }
171
- if (Number.isInteger) {
172
- if (!Number.isInteger(Number(value))) {
173
- throw new ArithmeticException(`Invalid value: '${value}' is a float`);
174
- }
175
- } else if ((value % 1) !== 0) { // IE11 does not support Number.isInteger
171
+ if (!Number.isInteger(Number(value))) {
176
172
  throw new ArithmeticException(`Invalid value: '${value}' is a float`);
177
173
  }
178
174
  if (value > MAX_SAFE_INTEGER || value < MIN_SAFE_INTEGER) {
package/src/nativeJs.js CHANGED
@@ -4,22 +4,16 @@
4
4
  */
5
5
 
6
6
  import { requireNonNull } from './assert';
7
- import { IllegalArgumentException } from './errors';
8
7
  import { Instant, ZoneId } from './js-joda';
9
8
 
10
9
  /**
11
10
  * Creates ZonedDateTime from a javascript Date or a moment instance.
12
- * @param {!(Date|moment)} date - a javascript Date or a moment instance
11
+ * @param {string} date - a javascript Date or a moment instance
13
12
  * @param {ZoneId} [zone = ZoneId.systemDefault()] - the zone of the returned ZonedDateTime, defaults to ZoneId.systemDefault()
14
13
  * @returns {ZonedDateTime}
15
14
  */
16
15
  export function nativeJs(date, zone = ZoneId.systemDefault()) {
17
16
  requireNonNull(date, 'date');
18
17
  requireNonNull(zone, 'zone');
19
- if(date instanceof Date) {
20
- return Instant.ofEpochMilli(date.getTime()).atZone(zone);
21
- } else if(typeof date.toDate === 'function' && date.toDate() instanceof Date) {
22
- return Instant.ofEpochMilli(date.toDate().getTime()).atZone(zone);
23
- }
24
- throw new IllegalArgumentException('date must be a javascript Date or a moment instance');
18
+ return Instant.ofEpochMilli(date.valueOf()).atZone(zone);
25
19
  }
@@ -12,13 +12,15 @@ export class ZoneRulesProvider {
12
12
  *
13
13
  * This returns the latest available rules for the zone ID.
14
14
  *
15
- * This method relies on time-zone data provider files that are configured.
15
+ * This method relies on `@js-joda/timezone` being imported first (for
16
+ * side effects).
16
17
  *
17
18
  * @param {string} zoneId
18
19
  * @return {ZoneRules}
19
20
  */
20
- static getRules(zoneId){
21
- throw new DateTimeException(`unsupported ZoneId:${zoneId}`);
21
+ // eslint-disable-next-line no-unused-vars
22
+ static getRules(_zoneId){
23
+ throw new DateTimeException('@js-joda/timezone not imported');
22
24
  }
23
25
 
24
26
 
@@ -1136,6 +1136,10 @@ export class Duration extends TemporalAmount {
1136
1136
  toMillis(): number;
1137
1137
  toMinutes(): number;
1138
1138
  toNanos(): number;
1139
+ toHoursPart(): number;
1140
+ toMinutesPart(): number;
1141
+ toSecondsPart(): number;
1142
+ toMillisPart(): number;
1139
1143
  toString(): string;
1140
1144
  units(): TemporalUnit[];
1141
1145
  withNanos(nanoOfSecond: number): Duration;
@@ -108,6 +108,10 @@ declare module "js-joda" {
108
108
  toMillis(): number;
109
109
  toMinutes(): number;
110
110
  toNanos(): number;
111
+ toHoursPart(): number;
112
+ toMinutesPart(): number;
113
+ toSecondspart(): number;
114
+ toMillisPart(): number;
111
115
  toString(): string;
112
116
  units(): any;
113
117
  withNanos(nanoOfSecond: number): Duration;