@js-joda/core 5.4.1 → 5.5.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.4.1",
3
+ "version": "5.5.0",
4
4
  "description": "a date and time library for javascript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,9 +31,9 @@
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_ie,sl_firefox,sl_ios_simulator\" --single-run=true",
34
+ "test-saucelabs": "npx karma start --reporters=\"dots,saucelabs\" --browsers=\"sl_chrome,sl_ie,sl_firefox\" --single-run=true",
35
35
  "test-ci": "npm run build-dist && npm run test && npm run test-browser && npm run test-ts-definitions && npm run test-coverage",
36
- "test-ts-definitions": "TS_NODE_PROJECT='test/typescript_definitions/tsconfig.json' NODE_ENV=test mocha --timeout 5000 --require ts-node/register ./test/typescript_definitions/*.ts",
36
+ "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
37
  "build-dist": "npx rollup -c rollup.config.js",
38
38
  "build-md-toc": "npx markdown-toc -i CheatSheet.md",
39
39
  "build-gz-check": "gzip -kf dist/js-joda.min.js && ls -alh ./dist/js-joda.min.js*",
@@ -47,5 +47,6 @@
47
47
  "nyc": {
48
48
  "sourceMap": false,
49
49
  "instrument": false
50
- }
50
+ },
51
+ "gitHead": "7388db45c1ac3aee66730d764075ede1429c38db"
51
52
  }
package/src/js-joda.js CHANGED
@@ -59,6 +59,7 @@ import { ValueRange } from './temporal/ValueRange';
59
59
  import { DateTimeFormatter } from './format/DateTimeFormatter';
60
60
  import { DateTimeFormatterBuilder } from './format/DateTimeFormatterBuilder';
61
61
  import { DecimalStyle } from './format/DecimalStyle';
62
+ import { ParsePosition } from './format/ParsePosition';
62
63
  import { ResolverStyle } from './format/ResolverStyle';
63
64
  import { SignStyle } from './format/SignStyle';
64
65
  import { TextStyle } from './format/TextStyle';
@@ -76,7 +77,7 @@ import { StringBuilder } from './format/StringBuilder';
76
77
  import * as assert from './assert';
77
78
 
78
79
  import { convert } from './convert';
79
- import { nativeJs } from './temporal/NativeJsTemporal';
80
+ import { nativeJs } from './nativeJs';
80
81
  import { bindUse } from './use';
81
82
 
82
83
  const _ = {
@@ -111,6 +112,7 @@ const jsJodaExports = {
111
112
  OffsetDateTime,
112
113
  Month,
113
114
  MonthDay,
115
+ ParsePosition,
114
116
  Period,
115
117
  Year,
116
118
  YearConstants,
@@ -179,6 +181,7 @@ export {
179
181
  OffsetTime,
180
182
  OffsetDateTime,
181
183
  Period,
184
+ ParsePosition,
182
185
  Year,
183
186
  YearConstants,
184
187
  YearMonth,
@@ -0,0 +1,27 @@
1
+ /*
2
+ * @copyright (c) 2015-present, Philipp Thürwächter, Pattrick Hüper & js-joda contributors
3
+ * @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
4
+ */
5
+
6
+ import { requireNonNull } from './assert';
7
+ import { IllegalArgumentException } from './errors';
8
+ import { Instant, ZoneId } from './js-joda';
9
+
10
+ /**
11
+ * Creates ZonedDateTime from a javascript Date or a moment instance.
12
+ * @param {!(Date|moment)} date - a javascript Date or a moment instance
13
+ * @param {ZoneId} [zone = ZoneId.systemDefault()] - the zone of the returned ZonedDateTime, defaults to ZoneId.systemDefault()
14
+ * @returns {ZonedDateTime}
15
+ */
16
+ export function nativeJs(date, zone = ZoneId.systemDefault()) {
17
+ requireNonNull(date, 'date');
18
+ requireNonNull(zone, 'zone');
19
+ switch (date.constructor.name) {
20
+ case 'Date':
21
+ return Instant.ofEpochMilli(date.getTime()).atZone(zone);
22
+ case 'Moment':
23
+ return Instant.ofEpochMilli(date.valueOf()).atZone(zone);
24
+ default:
25
+ throw new IllegalArgumentException('date must be a javascript Date or a moment instance');
26
+ }
27
+ }
@@ -812,7 +812,7 @@ class Unit extends TemporalUnit {
812
812
  }
813
813
 
814
814
  toString() {
815
- return name;
815
+ return this._name;
816
816
  }
817
817
  }
818
818
 
@@ -2478,7 +2478,7 @@ export abstract class ChronoZonedDateTime extends Temporal {
2478
2478
  // SUPPORT
2479
2479
  // ----------------------------------------------------------------------------
2480
2480
 
2481
- export function nativeJs(date: Date | any, zone?: ZoneId): TemporalAccessor;
2481
+ export function nativeJs(date: Date | any, zone?: ZoneId): ZonedDateTime;
2482
2482
 
2483
2483
  export function convert(
2484
2484
  temporal: LocalDate | LocalDateTime | ZonedDateTime | Instant,
@@ -1,105 +0,0 @@
1
- /*
2
- * @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
3
- * @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
4
- */
5
-
6
- import { assert, requireNonNull } from '../assert';
7
- import { UnsupportedTemporalTypeException } from '../errors';
8
-
9
- import { Instant } from '../Instant';
10
- import { LocalDate } from '../LocalDate';
11
- import { LocalTime } from '../LocalTime';
12
- import { MathUtil } from '../MathUtil';
13
- import { ZoneId } from '../ZoneId';
14
-
15
- import { ChronoField } from './ChronoField';
16
- import { TemporalQueries } from './TemporalQueries';
17
- import { TemporalAccessor } from './TemporalAccessor';
18
-
19
- /**
20
- * A wrapper around a native javascript Date instance that
21
- * implements TemporalAccessor functionality
22
- */
23
- class NativeJsTemporal extends TemporalAccessor {
24
-
25
- /**
26
- * @param {!(Date|moment)} date - a javascript Date or a moment instance
27
- * @param {ZoneId} [zone=ZoneId.systemDefault()] - the zone of the temporal, defaults to ZoneId.systemDefault()
28
- * @private
29
- */
30
- constructor(date, zone=ZoneId.systemDefault()){
31
- super();
32
- this._zone = zone;
33
- if(date instanceof Date) {
34
- this._epochMilli = date.getTime();
35
- return;
36
- } else if(typeof date.toDate === 'function' && date.toDate() instanceof Date) {
37
- // it's a moment
38
- this._epochMilli = date.toDate().getTime();
39
- return;
40
- }
41
- assert(false, 'date must be either a javascript date or a moment');
42
- }
43
-
44
- /**
45
- * @param {TemporalQuery} query the query to invoke, not null
46
- * @return {*} the query result, null may be returned (defined by the query)
47
- * @throws DateTimeException if unable to query
48
- */
49
- query(query) {
50
- requireNonNull(query, 'query');
51
- if (query === TemporalQueries.localDate()) {
52
- return LocalDate.ofInstant(Instant.ofEpochMilli(this._epochMilli), this._zone);
53
- } else if(query === TemporalQueries.localTime()){
54
- return LocalTime.ofInstant(Instant.ofEpochMilli(this._epochMilli), this._zone);
55
- } else if(query === TemporalQueries.zone()){
56
- return this._zone;
57
- }
58
- return super.query(query);
59
- }
60
-
61
- /**
62
- *
63
- * @param {TemporalField} field
64
- * @returns {number}
65
- */
66
- get(field) {
67
- return this.getLong(field);
68
- }
69
-
70
- /**
71
- *
72
- * @param {!TemporalField} field
73
- * @returns {number}
74
- */
75
- getLong(field) {
76
- requireNonNull(field, 'field');
77
- if (field instanceof ChronoField) {
78
- switch (field) {
79
- case ChronoField.NANO_OF_SECOND: return MathUtil.floorMod(this._epochMilli, 1000) * 1000000;
80
- case ChronoField.INSTANT_SECONDS: return MathUtil.floorDiv(this._epochMilli, 1000);
81
- }
82
- throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
83
- }
84
- return field.getFrom(this);
85
- }
86
-
87
- /**
88
- *
89
- * @param {TemporalField} field
90
- * @returns {boolean}
91
- */
92
- isSupported(field){
93
- return field === ChronoField.INSTANT_SECONDS || field === ChronoField.NANO_OF_SECOND;
94
- }
95
- }
96
-
97
- /**
98
- *
99
- * @param {!(Date|moment)} date - a javascript Date or a moment instance
100
- * @param {ZoneId} [zone=ZoneId.systemDefault()] - the zone of the temporal, defaults to ZoneId.systemDefault()
101
- * @returns {NativeJsTemporal}
102
- */
103
- export function nativeJs(date, zone){
104
- return new NativeJsTemporal(date, zone);
105
- }