Socket
Socket
Sign inDemoInstall

js-joda

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-joda - npm Package Compare versions

Comparing version 0.9.1 to 0.9.3

1

benchmark/node-init.js

@@ -0,1 +1,2 @@

//global.JSJoda = require('../dist/js-joda');
global.JSJoda = require('js-joda');

@@ -2,0 +3,0 @@ global.moment = require('moment');

4

benchmark/package.json
{
"name": "js-joda-benchmark",
"version": "0.9.1",
"version": "0.9.2",
"description": "",

@@ -21,3 +21,3 @@ "main": "benchmark.js",

"benchmark": "^2.1.0",
"js-joda": "^0.3.14",
"js-joda": "^0.9.1",
"lodash": "^4.5.1",

@@ -24,0 +24,0 @@ "moment": "^2.11.2"

@@ -8,5 +8,15 @@ if(typeof require === 'function') { require('../node-init'); }

})
// check the code at LocalDateTime.now. there is a strategy for optimizing .now()
.add('js-joda LocalDateTime ', function() {
JSJoda.LocalDateTime.now();
})
.add('js-joda LocalTime ', function() {
JSJoda.LocalTime.now();
})
.add('js-joda LocalDate ', function() {
JSJoda.LocalDate.now();
})
.add('js-joda ZonedDateTime ', function() {
JSJoda.ZonedDateTime.now();
})
.add('moment', function() {

@@ -13,0 +23,0 @@ moment();

@@ -61,3 +61,3 @@ js-joda Cheat sheet

The API is using a consistent method prefixes.
The API is using a set of consistent method prefixes.

@@ -72,3 +72,3 @@ - of - static factory method

- at - combines this object with another, such as date.atTime(time)
- getter for instance properties are omitting the get keyword, e.q. localDate.year()
- getter methods for instance properties are omitting the get keyword, e.q. localDate.year()

@@ -78,3 +78,3 @@ ## Basic concepts

The API is immutable, an existing instance is never changed, all manipulating methods as parse/ with/ plus/ minus/ to/ at are returning new instances.
An existing instance is always valid. Instead of returning null or invalid values, exceptions are thrown.
An existing instance is always valid. Instead of returning null or invalid values, exceptions are thrown.

@@ -93,3 +93,3 @@ ## LocalDate

// obtain the current date in the utc timezone, e.g. 2016-02-23
LocalDate.now(Clock.systemUTC());
LocalDate.now(Clock.systemUTC());

@@ -159,3 +159,3 @@ // obtain an instance of LocalDate from an ISO8601 formatted text string

d.isoWeekOfWeekyear(); // 51, is the same as above
d.isoWeekOfWeekyear(); // 51, is the same as above
d.isoWeekyear(); // 2016

@@ -179,3 +179,3 @@

### Adding to/ subtracting from a LocalDate
```javascript

@@ -185,11 +185,11 @@

// add/ subtract 366 days
// add/ subtract 366 days
d.plusDays(366); // '2017-02-23'
d.minusDays(366); // '2015-02-22'
// add/ subtract 12 months
// add/ subtract 12 months
d.plusMonths(12); // '2017-02-23'
d.minusMonths(12); // '2015-02-23'
// add/ subtract 4 weeks
// add/ subtract 4 weeks
d.plusWeeks(4); // '2016-03-22'

@@ -201,3 +201,3 @@ d.minusWeeks(4); // '2016-01-26'

d.minusYears(1); // '2015-02-23'
// add/ subtract 30 years

@@ -228,3 +228,3 @@ d.plus(3, ChronoUnit.DECADES); // '2046-02-23'

// set the year to beginning of era
// set the year to beginning of era
d.withYear(1); // '0001-12-24'

@@ -313,3 +313,3 @@

TemporalAdjusters provides compact business logic for date based temporals such as LocalDate, LocalDateTime or ZonedDateTime.
TemporalAdjusters provide compact business logic for date based temporals such as LocalDate, LocalDateTime or ZonedDateTime.

@@ -349,3 +349,3 @@ ```javascript

// obtain the current time in the utc timezone, e.g. '09:29:05.743'
LocalTime.now(Clock.systemUTC());
LocalTime.now(Clock.systemUTC());

@@ -391,3 +391,3 @@ // obtain an instance of LocalTime from an ISO8601 formatted text string

### Adding to/ subtracting from a LocalTime instance
```javascript

@@ -397,15 +397,15 @@

// add/ subtract 12 hours
// add/ subtract 12 hours
t.plusHours(12); // '23:55:42'
t.minusHours(12); // '23:55:42'
// add/ subtract 30 minutes
// add/ subtract 30 minutes
t.plusMinutes(30); // '12:25:42'
t.minusMinutes(30); // '11:25:42'
// add/ subtract 30 seconds
// add/ subtract 30 seconds
t.plusSeconds(30); // '11:56:12'
t.minusSeconds(30); // '11:55:12'
// add/ subtract 1.000.000 nanos (1 milli second)
// add/ subtract 1.000.000 nanos (1 milli second)
t.plusNanos(1000000); // '11:56:42.001'

@@ -487,3 +487,3 @@ t.minusNanos(1000000); // '11:55:41.999'

### Distance between times
### Distance between times

@@ -502,3 +502,3 @@ ```javascript

### Convert a LocalTime from a javascript Date or moment
### Convert a LocalTime from a javascript Date or moment

@@ -522,3 +522,3 @@ ```javascript

A LocalTime represents a date-time without a time-zone in the ISO-8601 calendar system, such as '2007-12-03T10:15:30'.
A LocalDateTime represents a date-time without a time-zone in the ISO-8601 calendar system, such as '2007-12-03T10:15:30'.

@@ -533,3 +533,3 @@ ### Create a LocalDateTime instance

// obtain the current date and time in the utc timezone
LocalDateTime.now(Clock.systemUTC());
LocalDateTime.now(Clock.systemUTC());

@@ -545,6 +545,6 @@ // obtain an instance of LocalDateTime from an ISO8601 formatted text string

// TODO milestone 1
// obtain an instance of LocalDateTime from epoch seconds and a ZoneOffset
// LocalTime.ofEpochSecond() //
// LocalTime.ofInstant() //
LocalDateTime.ofEpochSecond(0, ZoneOffset.UTC) // "1970-01-01T00:00"
LocalDateTime.ofInstant(Instant.now()) // current local date-time
LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC) // current local utc date-time

@@ -604,3 +604,3 @@ ```

### Adding to/ subtracting from a LocalDateTime instance
```javascript

@@ -610,11 +610,11 @@

// add/ subtract 366 days
// add/ subtract 366 days
dt.plusDays(366); // '2017-02-26T23:55:42.123'
dt.minusDays(366); // '2015-02-25T23:55:42.123'
// add/ subtract 12 months
// add/ subtract 12 months
dt.plusMonths(12); // '2017-02-26'
dt.minusMonths(12); // '2015-02-26'
// add/ subtract 4 weeks
// add/ subtract 4 weeks
dt.plusWeeks(4); // '2016-03-25T23:55:42.123'

@@ -626,3 +626,3 @@ dt.minusWeeks(4); // '2016-01-29T23:55:42.123'

dt.minusYears(1); // '2015-02-26T23:55:42.123'
// add/ subtract 30 years

@@ -636,15 +636,15 @@ dt.plus(3, ChronoUnit.DECADES); // '2046-02-26T23:55:42.123'

// add/ subtract 12 hours
// add/ subtract 12 hours
dt.plusHours(12); // '2016-02-27T11:55:42.123'
dt.minusHours(12); // '2016-02-26T11:55:42.123'
// add/ subtract 30 minutes
// add/ subtract 30 minutes
dt.plusMinutes(30); // '2016-02-27T00:25:42.123'
dt.minusMinutes(30); // '2016-02-26T23:25:42.123'
// add/ subtract 30 seconds
// add/ subtract 30 seconds
dt.plusSeconds(30); // '2016-02-26T23:56:12.123'
dt.minusSeconds(30); // '2016-02-26T23:55:12.123'
// add/ subtract 1.000.000 nanos (1 milli second)
// add/ subtract 1.000.000 nanos (1 milli second)
dt.plusNanos(1000000); // '2016-02-26T23:55:42.124'

@@ -729,3 +729,3 @@ dt.minusNanos(1000000); // '2016-02-26T23:55:42.122'

### Distance between local dates and times
### Distance between local dates and times

@@ -748,3 +748,3 @@ ```javascript

### Convert from a javascript Date or moment
### Convert from a javascript Date or moment

@@ -767,15 +767,15 @@ ```javascript

ZonedDateTime represents a date-time with a time-zone in the ISO-8601 calendar system. Without the iana tzdb loaded,
ZonedDateTime only supports time-zones with a fixed Offset such as `UTC` or `UTC+02:00` and the system default time-zone `SYSTEM`.
ZonedDateTime represents a date-time with a time-zone in the ISO-8601 calendar system. Without support for loading iana time-zone databases,
ZonedDateTime currently only supports time-zones with a fixed Offset such as `UTC` or `UTC+02:00` and the system default time-zone `SYSTEM`.
### The system default time zone
The `SYSTEM` time-zone is a NON standard zone-id, that is introduced by js-joda because the javascript spec do not provide an api
for the system default zone-id. The javascript spec only provides the system default tome-zone offset for a point in the timeline
(Date.prototype.getTimezoneOffset()).
The `SYSTEM` time-zone is a NON standard zone-id, that is introduced by js-joda because the javascript spec does not provide an API
for the system default zone-id. The javascript spec only provides the system default time-zone offset for a point in the timeline
(Date.prototype.getTimezoneOffset()).
It is not recommended to exchange zoned-date-times with the SYSTEM zone-id between javascript engines,
because the default time-zone may differ on the other machine. Before a ZonedDateTime is exchanged,
It is not recommended to exchange zoned-date-times with the SYSTEM zone-id between javascript engines,
because the default time-zone may differ on other machines. Before a ZonedDateTime is exchanged,
it should be converted to a fixed offset zone.
```javascript

@@ -788,3 +788,3 @@

ZonedDateTime.now().withFixedOffsetZone().toString(); // e.g. 2016-03-18T12:38:23.561+01:00
```

@@ -802,10 +802,10 @@

// get now with a fixed offset time-zone
// get now with a fixed offset time-zone
ZonedDateTime.now(ZoneId.of('UTC-05:00')).toString(); // e.g. 2016-03-18T06:38:23.561-05:00[UTC-05:00]
// parse a date time with a time tone ISO String
ZonedDateTime.parse('2016-03-18T12:38:23.561+01:00[SYSTEM]');
ZonedDateTime.parse('2016-03-18T12:38:23.561+01:00');
ZonedDateTime.parse('2016-03-18T11:38:23.561Z');
ZonedDateTime.parse('2016-03-18T06:38:23.561-05:00[UTC-05:00]');
// parse a date time with a time zone ISO String
ZonedDateTime.parse('2016-03-18T12:38:23.561+01:00[SYSTEM]');
ZonedDateTime.parse('2016-03-18T12:38:23.561+01:00');
ZonedDateTime.parse('2016-03-18T11:38:23.561Z');
ZonedDateTime.parse('2016-03-18T06:38:23.561-05:00[UTC-05:00]');

@@ -840,7 +840,7 @@ // create from a LocalDate(Time)

Check the examples for LocalDate and LocalDateTime. ZonedDateTime implements the same methods as LocalDateTime
Check the examples for LocalDate and LocalDateTime. ZonedDateTime implements the same methods as LocalDateTime
for getting or setting values.
The calculation for date and time units differ. Date units operate on the local time-line. Time units operate on the instant time-line.
The following example shows the difference for a daylight saving transition.
The calculation for date and time units differ. Date units operate on the local time-line. Time units operate on the instant time-line.
The following example shows the difference for a daylight saving transition.

@@ -867,4 +867,4 @@ ```javascript

// parse and format ISO8601 period strings
Period.parse('P1Y10M').toString(); // 'P1Y10M'
Period.parse('P1Y10M').toString(); // 'P1Y10M'
// obtain a Period of 10 years, 5 month and 30 days

@@ -925,4 +925,4 @@ Period.of(10, 5, 30).toString(); // "P10Y5M30D"

js-joda is easy extend-able, it allows you to create your own custom domain models or formatter. check the temporal interface documentation
at temporal directory for more information.
js-joda is easily extendable, it allows you to create your own custom domain models or formatter. Check the temporal interface documentation
in the temporal directory for more information.

@@ -941,11 +941,10 @@ ### Custom temporal adjuster

### Custom temporal fields and temporal units
### Custom temporal fields and temporal units
a good point to start is temporal/IsoFields as an example how to implement custom fields and units.
A good starting point is temporal/IsoFields as an example how to implement custom fields and units.
IsoFields implements fields and units for an ISO week based year.
### Custom formatter and queries
The following example, is a kind of the opposite of a domain driven approach.
It implements a date-time parser that parses a local date with an optional local time.
The following example implements a date-time parser that parses a local date with an optional local time.
the temporal query returns either a LocalDate or a LocalDateTime, depending on the parsed fields.

@@ -956,11 +955,11 @@

// build a custom date time formatter where the time field is optional
var OPTIONAL_FORMATTER = new DateTimeFormatterBuilder().parseCaseInsensitive()
.append(DateTimeFormatter.ISO_LOCAL_DATE)
.optionalStart()
.appendLiteral('T').append(DateTimeFormatter.ISO_LOCAL_TIME)
var OPTIONAL_FORMATTER = new DateTimeFormatterBuilder().parseCaseInsensitive()
.append(DateTimeFormatter.ISO_LOCAL_DATE)
.optionalStart()
.appendLiteral('T').append(DateTimeFormatter.ISO_LOCAL_TIME)
.toFormatter();
// create a temporal query that create a new Temporal depending on the existing fields
dateOrDateTimeQuery = {
queryFrom: function(temporal){
dateOrDateTimeQuery = {
queryFrom: function(temporal){
var date = temporal.query(TemporalQueries.localDate());

@@ -972,3 +971,3 @@ var time = temporal.query(TemporalQueries.localTime());

}
localDate = OPTIONAL_FORMATTER.parse('2012-12-24', dateOrDateTimeQuery);

@@ -979,1 +978,5 @@ localDateTime = OPTIONAL_FORMATTER.parse('2012-12-24T23:59', dateOrDateTimeQuery);

<script src="https://cdn.jsdelivr.net/auto-toc.js/0.0.5/dist.js"></script>
<script>
autoToc('.content', '.toc-placeholder', {ignore: ['js-joda Cheat sheet', 'Table of content']});
</script>
{
"name": "js-joda",
"version": "0.9.1",
"version": "0.9.3",
"description": "a date and time library for javascript",

@@ -19,3 +19,3 @@ "repository": {

"build-dist": "./node_modules/.bin/webpack --progress --colors --bail && DIST_MIN=1 ./node_modules/.bin/webpack --progress --colors --bail",
"build-readme2html": "mkdir -p build && ./node_modules/.bin/marked -i README.md -o build/README.html && ./node_modules/.bin/markdown-toc -i CheatSheet.md && ./node_modules/.bin/marked -i CheatSheet.md -o build/CheatSheet.html"
"build-md-toc": "./node_modules/.bin/markdown-toc -i CheatSheet.md"
},

@@ -48,3 +48,2 @@ "keywords": [

"markdown-toc": "^0.12.3",
"marked": "^0.3.5",
"mocha": "^2.4.5",

@@ -51,0 +50,0 @@ "phantomjs": "^2.1.3",

@@ -10,26 +10,47 @@ Immutable data and time library for javascript

js-joda, a port of the ThreeTen immutable data and time library to javascript. It provides a simple and clean API based on the ISO8601 calendar.
Joda-Time (the predecessor project) used to be the de facto standard date and time library for Java and is the base for JSR-310 that became part of Java SE 8 in the java.time package.
+ **js-joda** is an **immutable data and time library** for javascript. It provides a **simple, domain-driven and clean API** based on the **ISO8601** calendar.
+ js-joda has a lightweight footprint, only **36 kB minified and compressed**, no third party dependencies.
+ js-joda is **fast**. It is about 2 to 10 times faster than other javascript date libraries.
+ js-joda supports **ECMAScript 5** browsers down to ie9.
+ js-joda is a **port of the threeten** backport **aka Joda-Time**, the predecessor project of threetenbp, that is the base for JSR-310 implementation of the Java SE 8 java.time package.
+ js-joda is **robust and stable**. We ported more then 1500 test-cases with a lots of test-permutations from the threetenbp project.
We run the automated karma test-suite against Firefox, Chrome, Node and phantomjs.
## Why yet another javascript date and time library
+ Popular javascript date libraries like moment or date-utils are wrappers around the native javascript Date object,
providing syntactic sugar. The native Date object always consist of a date, time and a timezone part.
In opposite to that, js-joda is a standalone date and time implementation.
+ Popular javascript date libraries like moment or date-utils are wrappers around the native javascript Date object,
providing syntactic sugar. The native Date object always consist of a date, time and a timezone part.
In opposite to that, js-joda is a standalone date and time implementation.
+ The API has a domain-driven design with classes for the different use cases, like LocalDate, ZonedDateTime or Period.
For examples LocalDate allows to handle dates like birthdays or holidays in a clean and error-safe way,
For examples LocalDate allows to handle dates like birthdays or holidays in a clean and error-safe way,
especially if these dates are persisted to an external server.
+ js-joda is immutable. Immutability aligns well with pure functions and
with the architecture of frameworks like React and Flux.
with the architecture of frameworks like React and Flux.
+ js-joda is a port of the sophisticated, robust and domain-driven API of Joda-Time (to be more precise of the ThreeTen-Backport of the Java SE 8 java.time package).
## The js-joda domain models
+ **LocalDate** represents a date without a time and time-zone in the ISO-8601 calendar system, such as 2007-12-24.
+ **LocalTime** represents a time without time-zone in the ISO-8601 calendar system such as '11:55:00'.
+ **LocalDateTime** is a description of the date (LocalDate), as used for birthdays, combined with the local time (LocalTime) as seen on a wall clock.
+ **ZonedDateTime** is a date-time with a time-zone in the ISO-8601 calendar system, such as 2007-12-24T16:15:30+01:00 UTC+01:00.
+ **Instant** is an instantaneous point on the time-line measured from the epoch of *1970-01-01T00:00:00Z* in epoch-seconds and nanosecond-of-second.
+ **Duration** is a time-based amount of time, such as '34.5 seconds'.
+ **Period** is a date-based amount of time in the ISO-8601 calendar system, such as '2 years, 3 months and 4 days'.
## Getting started
The library is in a very early state, far away from productive.
But you are very welcome to play around with js-joda and to give your feedback.
Please check the tests and the API Documentation for the current state of development.
### Node

@@ -42,10 +63,10 @@

Then require it to any module
var LocalDate = require('js-joda').LocalDate;
var d = LocalDate.parse('2012-12-24').atStartOfDay().plusMonths(2); // 2013-02-24T00:00:00
### Browser
To use js-joda from a browser, download either dist/js-joda.min.js or dist/js-joda.js (with sourcemaps for development)
To use js-joda from a browser, download either dist/js-joda.min.js or dist/js-joda.js (with sourcemaps for development)

@@ -59,6 +80,6 @@ Then add it as a script tag to your page

</script>
## Documentation
+ [Cheat Sheet](CheatSheet.md) Quick start guide
+ [Cheat Sheet](CheatSheet.md) Quick start guide
+ [API](https://doc.esdoc.org/github.com/pithu/js-joda/) ESDoc generated API documentation hosted by the ESDoc Hosting Service

@@ -70,17 +91,31 @@ + [js-joda Homepage](http://pithu.github.io/js-joda/) Project homepage

### Milestone 1
Our current plan is to have a first milestone with LocalDate, LocalDateTime, Instant, Duration and Period working.
The result of the first milestone will be a fully functional Date/Time library, converting from and to ISO8601, with UTC and system default timezone.
We reached milestone 1 with version v1.0.0 supporting the domain models LocalDate, LocalDateTime, ZonedDateTime, Instant, Duration
and Period converting from and to ISO8601. ZonedDateTime (without support for loading iana time-zone databases) currently supports
only fixed offsets like UTC or UTC+02:00 and the system default time zone.
### Future Milestones
Any further timezone converting and localization is not part of the first milestone and will be saved for later. This might also be an extra package
to reduce library size if Timezone functionality is not needed.
Any further timezone converting and localization is not part of the first milestone and will be saved for later.
This might also be an extra package to reduce library size if Timezone functionality is not needed.
## Contributing
Contributions are always welcome. Before contributing please read the [code of conduct](http://contributor-covenant.org/version/1/4/) &
search the issue tracker. We use GitHub issues. Your issue may have already been discussed or fixed.
To contribute, fork js-joda, commit your changes, & send a pull request.
By contributing to js-joda, you agree that your contributions will be licensed under its BSD license.
Note that pull requests and issues will only be considered so far as matching the threeten backport API.
Additional requested features will be rejected.
## License
Joda time is the base for JSR-310 that became part of Java SE 8 in the java.time package.
JSR-310 is a new implementation with an API 'inspired by Joda-Time' but improvements on some design flaws (see http://blog.joda.org/2009/11/why-jsr-310-isn-joda-time_4941.html)
JSR-310 is a new implementation with an API 'inspired by Joda-Time' but improvements on some design flaws (see
http://blog.joda.org/2009/11/why-jsr-310-isn-joda-time_4941.html)
js-joda is using the ThreeTen-Backport implementation (http://www.threeten.org/threetenbp/) as a reference base for implementation.
This allows us to release js-joda under the BSD License while the OpenJDK java.time implementation is under GNU GPL+linking exception.
js-joda is using the ThreeTen-Backport implementation (http://www.threeten.org/threetenbp/) as a reference base for implementation.
This allows us to release js-joda under the BSD License while the OpenJDK java.time implementation is under GNU GPL+linking exception.
The API of the ThreeTen-Backport is mostly identical to the official Java SE 8 API from the view of our javascript port.

@@ -96,7 +131,5 @@

+ The author of joda time and the lead architect of the JSR-310 is Stephen Colebourne.
+ The author of joda time and the lead architect of the JSR-310 is Stephen Colebourne.
The API of this project (as far as possible with javascript), a lot of implementation details and documentation
The API of this project (as far as possible with javascript), a lot of implementation details and documentation
are just copied but never equalled.

@@ -209,2 +209,6 @@ /**

}
millis(){
return this._instant.toEpochMilli();
}

@@ -211,0 +215,0 @@ zone() {

@@ -57,3 +57,2 @@ /**

*/
//TODO: private ?
constructor(seconds, nanos) {

@@ -78,3 +77,3 @@ super();

static ofDays(days) {
return Duration.create(MathUtil.safeMultiply(days, LocalTime.SECONDS_PER_DAY), 0);
return Duration._create(MathUtil.safeMultiply(days, LocalTime.SECONDS_PER_DAY), 0);
}

@@ -94,3 +93,3 @@

static ofHours(hours) {
return Duration.create(MathUtil.safeMultiply(hours, LocalTime.SECONDS_PER_HOUR), 0);
return Duration._create(MathUtil.safeMultiply(hours, LocalTime.SECONDS_PER_HOUR), 0);
}

@@ -110,3 +109,3 @@

static ofMinutes(minutes) {
return Duration.create(MathUtil.safeMultiply(minutes, LocalTime.SECONDS_PER_MINUTE), 0);
return Duration._create(MathUtil.safeMultiply(minutes, LocalTime.SECONDS_PER_MINUTE), 0);
}

@@ -137,3 +136,3 @@

var nos = MathUtil.floorMod(nanoAdjustment, LocalTime.NANOS_PER_SECOND);
return Duration.create(secs, nos);
return Duration._create(secs, nos);
}

@@ -157,3 +156,3 @@

}
return Duration.create(secs, mos * 1000000);
return Duration._create(secs, mos * 1000000);
}

@@ -177,3 +176,3 @@

}
return this.create(secs, nos);
return this._create(secs, nos);
}

@@ -344,3 +343,3 @@

try {
return Duration.create(negate, daysAsSecs, hoursAsSecs, minsAsSecs, seconds, nanos);
return Duration._create(negate, daysAsSecs, hoursAsSecs, minsAsSecs, seconds, nanos);
} catch (ex) {

@@ -390,13 +389,11 @@ throw new DateTimeParseException('Text cannot be parsed to a Duration: overflow', text, 0, ex);

*/
static create() {
if (arguments.length === 1) {
return Duration.createSeconds(arguments[0]);
} else if (arguments.length === 2) {
return Duration.createSecondsNanos(arguments[0], arguments[1]);
static _create() {
if (arguments.length <= 2) {
return Duration._createSecondsNanos(arguments[0], arguments[1]);
} else {
return Duration.createNegateDaysHoursMinutesSecondsNanos(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
return Duration._createNegateDaysHoursMinutesSecondsNanos(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
}
}
static createNegateDaysHoursMinutesSecondsNanos(negate, daysAsSecs, hoursAsSecs, minsAsSecs, secs, nanos) {
static _createNegateDaysHoursMinutesSecondsNanos(negate, daysAsSecs, hoursAsSecs, minsAsSecs, secs, nanos) {
var seconds = MathUtil.safeAdd(daysAsSecs, MathUtil.safeAdd(hoursAsSecs, MathUtil.safeAdd(minsAsSecs, secs)));

@@ -415,32 +412,9 @@ if (negate) {

*/
static createSecondsNanos(seconds = 0, nanoAdjustment = 0) {
static _createSecondsNanos(seconds = 0, nanoAdjustment = 0) {
if ((seconds | nanoAdjustment) === 0) {
return Duration.ZERO;
}
// if seconds is a float, we need to adjust the nanos from it as well
if (seconds >= 0) {
nanoAdjustment += seconds % 1 * LocalTime.NANOS_PER_SECOND;
} else {
nanoAdjustment -= seconds % 1 * LocalTime.NANOS_PER_SECOND;
}
seconds = Math.floor(seconds);
nanoAdjustment = Math.round(nanoAdjustment);
return new Duration(seconds, nanoAdjustment);
}
/**
* Creates an instance of {@link Duration} from a number of seconds.
*
* @param {Number} seconds - the number of seconds, up to scale 9, positive or negative
* @return {!Duration}
* @throws ArithmeticException if numeric overflow occurs
*/
static createSeconds(seconds) {
let nanos = Math.round(seconds * Math.pow(10, 9));
let div = MathUtil.intDiv(nanos, LocalTime.NANOS_PER_SECOND);
let rem = MathUtil.intMod(nanos, LocalTime.NANOS_PER_SECOND);
return Duration.ofSeconds(div, rem);
}
//-----------------------------------------------------------------------

@@ -550,3 +524,3 @@ /**

withSeconds(seconds) {
return Duration.create(seconds, this._nanos);
return Duration._create(seconds, this._nanos);
}

@@ -568,3 +542,3 @@

ChronoField.NANO_OF_SECOND.checkValidIntValue(nanoOfSecond);
return Duration.create(this._seconds, nanoOfSecond);
return Duration._create(this._seconds, nanoOfSecond);
}

@@ -907,3 +881,7 @@

}
return Duration.create(MathUtil.safeMultiply(this.toSeconds(), multiplicand));
let secs = MathUtil.safeMultiply(this._seconds, multiplicand);
let nos = MathUtil.safeMultiply(this._nanos, multiplicand);
secs = secs + MathUtil.intDiv(nos, LocalTime.NANOS_PER_SECOND);
nos = MathUtil.intMod(nos, LocalTime.NANOS_PER_SECOND);
return Duration.ofSeconds(secs, nos);
}

@@ -914,3 +892,4 @@

* <p>
* This instance is immutable and unaffected by this method call.
* In opposite to the threeten implementation the division is realized by floating point not by
* fixed point arithmetic. Expect floating point rounding errors for {@link Duration.dividedBy}.
*

@@ -928,16 +907,9 @@ * @param {Number} divisor - the value to divide the duration by, positive or negative, not zero

}
return Duration.create(this.toSeconds() / divisor);
var secs = MathUtil.intDiv(this._seconds, divisor);
var secsMod = MathUtil.roundDown(((this._seconds/ divisor) - secs) * LocalTime.NANOS_PER_SECOND);
var nos = MathUtil.intDiv(this._nanos, divisor);
nos = secsMod + nos;
return Duration.ofSeconds(secs, nos);
}
/**
* Converts this duration to the total length in seconds and
* fractional nanoseconds expressed as a {@code BigDecimal}.
*
* @return {number} the total length of the duration in seconds, with a scale of 9, not null
*/
toSeconds() {
var nanoFloat = MathUtil.safeMultiply(this._nanos, Math.pow(10, -9));
return MathUtil.safeAdd(this._seconds, nanoFloat);
}
//-----------------------------------------------------------------------

@@ -1058,3 +1030,3 @@ /**

toDays() {
return this._seconds / LocalTime.SECONDS_PER_DAY;
return MathUtil.intDiv(this._seconds, LocalTime.SECONDS_PER_DAY);
}

@@ -1073,3 +1045,3 @@

toHours() {
return this._seconds / LocalTime.SECONDS_PER_HOUR;
return MathUtil.intDiv(this._seconds, LocalTime.SECONDS_PER_HOUR);
}

@@ -1088,3 +1060,3 @@

toMinutes() {
return this._seconds / LocalTime.SECONDS_PER_MINUTE;
return MathUtil.intDiv(this._seconds, LocalTime.SECONDS_PER_MINUTE);
}

@@ -1091,0 +1063,0 @@

@@ -848,3 +848,3 @@ /**

case ChronoUnit.NANOS: return this._nanosUntil(end);
case ChronoUnit.MICROS: return this._nanosUntil(end) / 1000;
case ChronoUnit.MICROS: return MathUtil.intDiv(this._nanosUntil(end), 1000);
case ChronoUnit.MILLIS: return MathUtil.safeSubtract(end.toEpochMilli(), this.toEpochMilli());

@@ -851,0 +851,0 @@ case ChronoUnit.SECONDS: return this._secondsUntil(end);

@@ -113,2 +113,24 @@ /**

/**
* Obtains the current time from the specified clock.
* If no argument is specified the system default clock is queried,
* if a zone-id is passed a system clock with the specified zone is queried.
* <p>
* This will query the specified clock to obtain the current time.
* Using this method allows the use of an alternate clock for testing.
* The alternate clock may be introduced using {@link Clock dependency injection}.
*
* @param {Clock|ZoneId} clockOrZone - the zone ID or clock to use, if null Clock.systemDefaultZone() is used.
* @return {LocalDateTime} the current time using the system clock, not null
*/
static now(clockOrZone) {
if (clockOrZone == null){
return LocalTime._now(Clock.systemDefaultZone());
} else if (clockOrZone instanceof Clock){
return LocalTime._now(clockOrZone);
} else {
return LocalTime._now(Clock.system(clockOrZone));
}
}
/**
* Obtains the current time from the specified clock.

@@ -123,3 +145,3 @@ * <p>

*/
static now(clock = Clock.systemDefaultZone()) {
static _now(clock = Clock.systemDefaultZone()) {
requireNonNull(clock, 'clock');// inline OffsetTime factory to avoid creating object and InstantProvider checks

@@ -126,0 +148,0 @@ return LocalTime.ofInstant(clock.instant(), clock.zone());

@@ -23,9 +23,3 @@ /**

var r = x/y;
if(r === 0){
return 0;
} else if(r < 0){
r = Math.ceil(r);
} else {
r = Math.floor(r);
}
r = MathUtil.roundDown(r);
return MathUtil.safeZero(r);

@@ -42,9 +36,3 @@ }

var r = x - MathUtil.intDiv(x, y) * y;
if(r === 0){
return 0;
} else if(r < 0){
r = Math.ceil(r);
} else {
r = Math.floor(r);
}
r = MathUtil.roundDown(r);
return MathUtil.safeZero(r);

@@ -55,2 +43,15 @@ }

*
* @param {number} r
* @returns {number}
*/
static roundDown(r){
if (r < 0) {
return Math.ceil(r);
} else {
return Math.floor(r);
}
}
/**
*
* @param {number} x

@@ -57,0 +58,0 @@ * @param {number} y

@@ -26,2 +26,12 @@ /*

/**
*
* @param {number} epochMilli
* @returns {ZoneOffset}
*/
offsetOfEpochMilli(epochMilli){
var offsetInMinutes = new Date(epochMilli).getTimezoneOffset();
return ZoneOffset.ofTotalMinutes(offsetInMinutes * -1);
}
/**
* This implementation is NOT returning the best value in a gap or overlap situation

@@ -28,0 +38,0 @@ * as specified at {@link ZoneRules.offsetOfLocalDateTime}.

@@ -51,2 +51,3 @@ /*

}
/**

@@ -59,3 +60,3 @@ * Gets the offset applicable at the specified instant in these rules.

*
* @param {Instant} instant the instant to find the offset for, not null, but null
* @param {Instant} instant - the instant to find the offset for, not null, but null
* may be ignored if the rules have a single offset for all instants

@@ -67,2 +68,16 @@ * @return {ZoneOffset} the offset, not null

}
/**
* Gets the offset applicable at the specified epochMilli in these rules.
*
* The method is for javascript performance optimisation.
*
* @param {number} epochMilli - the epoch millisecond to find the offset for, not null, but null
* may be ignored if the rules have a single offset for all instants
* @return {ZoneOffset} the offset, not null
*/
offsetOfEpochMilli(epochMilli){
abstractMethodFail('ZoneRules.offsetOfEpochMilli');
}

@@ -137,2 +152,6 @@ /**

offsetOfEpochMilli(){
return this._offset;
}
offsetOfLocalDateTime(){

@@ -139,0 +158,0 @@ return this._offset;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc