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.3.9 to 0.3.10

240

CheatSheet.md

@@ -87,6 +87,12 @@ js-joda Cheat sheet

// get the day of week aligned to the first day of month
// get other date based field like the aligned week of year
d.get(ChronoField.ALIGNED_WEEK_OF_YEAR); // 52
// or the day of week aligned to the first day of month
d.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH); // 3
d.withDayOfMonth(1).get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH); // 1
// TODO
// get week of week based year
dt.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); // 8
```

@@ -238,3 +244,3 @@

A LocalTime represents A time without time-zone in the ISO-8601 calendar system such as '10:15:30'
A LocalTime represents a time without time-zone in the ISO-8601 calendar system such as '10:15:30'

@@ -257,3 +263,3 @@ ### Create a LocalTime instance

// obtain an instance of LocalDate from a hour, minute, second and nano value
// obtain an instance of LocalTime from a hour, minute, second and nano value
LocalTime.of(23, 55) // '23:55'

@@ -264,3 +270,3 @@ LocalTime.of(23, 55, 42) // '23:55:42'

// obtain an instance of LoclTome from second of day
// obtain an instance of LocalTime from second of day
LocalTime.ofSecondOfDay(3666) // '01:01:06'

@@ -305,3 +311,3 @@

// add/ subtract 30 minutes
// add/ subtract 30 seconds
t.plusSeconds(30); // '11:56:12'

@@ -402,2 +408,224 @@ t.minusSeconds(30); // '11:55:12'

## LocalDateTime
A LocalTime represents a date-time without a time-zone in the ISO-8601 calendar system, such as '2007-12-03T10:15:30'.
### Create a LocalDateTime instance
```javascript
// obtain the current date and time in the system default timezone, e.g. '2016-02-26T10:29:05.743'
LocalDateTime.now();
// obtain the current date and time in the utc timezone
LocalDateTime.now(Clock.systemUTC());
// obtain an instance of LocalDateTime from an ISO8601 formatted text string
LocalDateTime.parse('2016-02-26T09:42'); // '2016-02-26T09:42'
LocalDateTime.parse('2016-02-26T09:42:42.123'); // '2016-02-26T09:42:42.123'
// obtain an instance of LocalDateTime from a year, month, dayOfMonth, hour, minute, second and nano value
LocalDateTime.of(2016,2,29); // "2016-02-29T00:00"
LocalDateTime.of(2016,2,29,12,55,42); // "2016-02-29T12:55:42"
LocalDateTime.of(2016,2,29,12,55,42,9) // "2016-02-29T12:55:42.000000009"
// TODO milestone 1
// obtain an instance of LocalDateTime from epoch seconds and a ZoneOffset
// LocalTime.ofEpochSecond() //
// LocalTime.ofInstant() //
```
### Get values from LocalTime
```javascript
var dt = LocalDateTime.parse('2016-02-26T23:55:42.123');
dt.toString(); // '2016-02-26T23:55:42.123' ISO8601 format
dt.year(); // 2016
dt.month(); // Month.FEBRUARY
dt.monthValue(); // 2
dt.dayOfMonth(); // 26
dt.hour(); // 23
dt.minute(); // 55
dt.second(); // 42
dt.nano(); // 123000000
dt.dayOfWeek(); // DayOfWeek.FRIDAY
dt.dayOfWeek().value(); // 5
dt.dayOfYear(); // 57
dt.toLocalDate().isLeapYear(); // true 2016 is a leap year
// obtain the LocalDate of the LocalDateTime
dt.toLocalDate()
// obtain the LocalTime of the LocalDateTime
dt.toLocalTime()
// get range of month
dt.toLocalDate().lengthOfMonth() // 29
dt.range(ChronoField.DAY_OF_MONTH); // ValueRange(1 - 29)
// get range of year
dt.toLocalDate().lengthOfYear() // 366
dt.range(ChronoField.DAY_OF_YEAR); // ValueRange(1 - 366)
// get other date based field like the aligned week of year
dt.get(ChronoField.ALIGNED_WEEK_OF_YEAR); // 9
// TODO
// get week of week based year
// dt.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); // 8
// get other time based fields
dt.get(ChronoField.SECOND_OF_DAY); // 86142
dt.get(ChronoField.MILLI_OF_SECOND); // 123
dt.get(ChronoField.HOUR_OF_AMPM); // 11
// any other date or time based ChronoField is allowed as param for get
```
### Adding to/ subtracting from a LocalDateTime instance
```javascript
var dt = LocalDateTime.parse('2016-02-26T23:55:42.123');
// 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
dt.plusMonths(12); // '2017-02-26'
dt.minusMonths(12); // '2015-02-26'
// add/ subtract 4 weeks
dt.plusWeeks(4); // '2016-03-25T23:55:42.123'
dt.minusWeeks(4); // '2016-01-29T23:55:42.123'
// add/ subtract 1 year to the parsed LocalDate and returns a new instance
dt.plusYears(1); // '2017-02-26T23:55:42.123'
dt.minusYears(1); // '2015-02-26T23:55:42.123'
// add/ subtract 30 years
dt.plus(3, ChronoUnit.DECADES); // '2046-02-26T23:55:42.123'
dt.minus(3, ChronoUnit.DECADES); // '1986-02-26T23:55:42.123'
// add subtract a Period of 3 Months and 3 Days
dt.plus(Period.ofMonths(3).plusDays(3)) // '2016-05-29T23:55:42.123'
dt.minus(Period.ofMonths(3).plusDays(3)) // '2015-11-23T23:55:42.123'
// 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
dt.plusMinutes(30); // '2016-02-27T00:25:42.123'
dt.minusMinutes(30); // '2016-02-26T23:25:42.123'
// 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)
dt.plusNanos(1000000); // '2016-02-26T23:55:42.124'
dt.minusNanos(1000000); // '2016-02-26T23:55:42.122'
// add/ subtract a time based unit
dt.plus(1, ChronoUnit.MILLIS); // '2016-02-26T23:55:42.124'
dt.plus(1, ChronoUnit.HALF_DAYS); // '2016-02-26T11:55:42.123'
// add/ subtract a duration of 30 hours and 45 minutes
dt.plus(Duration.ofHours(30).plusMinutes(45)); // '2016-02-28T06:40:42.123'
dt.minus(Duration.ofHours(30).plusMinutes(45)); // '2016-02-25T17:10:42.123'
```
### Alter certain fields of a LocalDateTime instance
```javascript
var dt = LocalDateTime.parse('2016-02-26T23:55:42.123');
// set the hour of day to 1
dt.withHour(1); // '2016-02-26T01:55:42.123'
// set the minute of hour to 1
dt.withMinute(1); // '2016-02-26T23:01:42.123'
// set the second of minute to 1
dt.withSecond(1); // '2016-02-26T23:55:01.123'
// set the nano of second to 1
dt.withNano(0); // '2016-02-26T23:55:42'
// set the MILLI_OF_SECOND to 51
dt.with(ChronoField.MILLI_OF_SECOND, 51) // '2016-02-26T23:55:42.051'
// set by a custom TemporalAdjusters
// sample of a custom adjuster that adjust to the next even second
var nextEvenSecond = { adjustInto: function(t){ return t.second() % 2 === 0 ? t.plusSeconds(2) : t.plusSeconds(1); } }
dt.with(nextEvenSecond) // '2016-02-26T23:55:44.123'
dt.plusSeconds(1).with(nextEvenSecond) // '2016-02-26T23:55:44.123'
```
### truncate a LocalDateTime instance
```javascript
var dt = LocalDateTime.parse('2016-02-26T23:55:42.123');
dt.truncatedTo(ChronoUnit.SECONDS); // '2016-02-26T23:55:42'
dt.truncatedTo(ChronoUnit.MINUTES); // '2016-02-26T23:55:00'
dt.truncatedTo(ChronoUnit.HOURS); // '2016-02-26T23:00'
dt.truncatedTo(ChronoUnit.HALF_DAYS); // '2016-02-26T12:00'
dt.truncatedTo(ChronoUnit.DAYS); // '2016-02-26T00:00'
```
### Compare LocalDateTime instances
```javascript
var dt1 = LocalDateTime.parse('2016-02-26T23:55:42.123');
var dt2 = dt1.plusHours(2);
dt1.isAfter(dt2); // false
dt1.isBefore(dt2); // true
dt1.equals(dt1.plusHours(0)); // true
dt1.equals(dt1.plusHours(1)); // false
dt1.compareTo(dt1) === 0; // true
dt1.compareTo(dt2) < 0; // true
dt2.compareTo(dt1) > 0; // true
dt1.hashCode(); // -2036645668
dt2.hashCode(); // 1459191821
dt1.hashCode() !== dt2.hashCode(); // true
```
### Distance between local dates and times
```javascript
var dt1 = LocalDateTime.parse('2016-02-26T23:55:42.123');
var dt2 = dt1.plusYears(6).plusMonths(12).plusHours(2).plusMinutes(42).plusSeconds(12);
// obtain the duration between the two dates
dt1.until(dt2, ChronoUnit.YEARS); // 7
dt1.until(dt2, ChronoUnit.MONTHS); // 84
dt1.until(dt2, ChronoUnit.WEEKS); // 356
dt1.until(dt2, ChronoUnit.DAYS); // 2557
dt1.until(dt2, ChronoUnit.HOURS); // 61370
dt1.until(dt2, ChronoUnit.MINUTES); // 3682242
dt1.until(dt2, ChronoUnit.SECONDS); // 220934532
```
## Period and Duration
...

2

package.json
{
"name": "js-joda",
"version": "0.3.9",
"version": "0.3.10",
"description": "a date and time library for javascript",

@@ -5,0 +5,0 @@ "repository": {

@@ -7,3 +7,3 @@ /**

import {assert} from '../assert';
import {assert, requireNonNull} from '../assert';

@@ -149,4 +149,4 @@ import {DateTimeParseException, NullPointerException} from '../errors';

parse(text, type) {
assert(text != null, 'text', NullPointerException);
assert(type != null, 'type', NullPointerException);
requireNonNull(text, 'text');
requireNonNull(type, 'type');
try {

@@ -153,0 +153,0 @@ var builder = this._parseToBuilder(text, null).resolve(this._resolverStyle, this._resolverFields);

@@ -1,5 +0,3 @@

/**
* @copyright (c) 2016, Philipp Thuerwaechter & Pattrick Hueper
* @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
*/
//! @copyright (c) 2016, Philipp Thuerwaechter & Pattrick Hueper
//! @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
//! @license BSD-3-Clause (see LICENSE in the root directory of this source tree)

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

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