Socket
Socket
Sign inDemoInstall

js-joda

Package Overview
Dependencies
1
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.7 to 0.3.8

src/temporal/Temporal.js

209

CheatSheet.md

@@ -97,25 +97,27 @@ js-joda Cheat sheet

var d = LocalDate.parse('2016-02-23');
// add/ subtract 366 days
LocalDate.parse('2016-02-23').plusDays(366); // '2017-02-23'
LocalDate.parse('2016-02-23').minusDays(366); // '2015-02-22'
d.plusDays(366); // '2017-02-23'
d.minusDays(366); // '2015-02-22'
// add/ subtract 12 months
LocalDate.parse('2016-02-23').plusMonths(12); // '2017-02-23'
LocalDate.parse('2016-02-23').minusMonths(12); // '2015-02-23'
d.plusMonths(12); // '2017-02-23'
d.minusMonths(12); // '2015-02-23'
// add/ subtract 4 weeks
LocalDate.parse('2016-02-23').plusWeeks(4); // '2016-03-22'
LocalDate.parse('2016-02-23').minusWeeks(4); // '2016-01-26'
d.plusWeeks(4); // '2016-03-22'
d.minusWeeks(4); // '2016-01-26'
// add/ subtract 1 year to the parsed LocalDate and returns a new instance
LocalDate.parse('2016-02-23').plusYears(1); // '2017-02-23'
LocalDate.parse('2016-02-23').minusYears(1); // '2015-02-23'
d.plusYears(1); // '2017-02-23'
d.minusYears(1); // '2015-02-23'
// add/ subtract 30 years
LocalDate.parse('2016-02-23').plus(3, ChronoUnit.DECADES); // '2046-02-23'
LocalDate.parse('2016-02-23').minus(3, ChronoUnit.DECADES); // '1986-02-23'
d.plus(3, ChronoUnit.DECADES); // '2046-02-23'
d.minus(3, ChronoUnit.DECADES); // '1986-02-23'
// add subtract a Period of 3 Months and 3 Days
LocalDate.parse('2016-02-23').plus(Period.ofMonths(3).plusDays(3)) // '2016-05-26'
LocalDate.parse('2016-02-23').minus(Period.ofMonths(3).plusDays(3)) // '2015-11-20'
d.plus(Period.ofMonths(3).plusDays(3)) // '2016-05-26'
d.minus(Period.ofMonths(3).plusDays(3)) // '2015-11-20'

@@ -172,5 +174,3 @@ ```

d1.isEqual(d2); // false
d1.isEqual(d1.plusDays(0)); // true
d1.equals(d2); // false
d1.equals(d1.plusDays(0)); // true

@@ -206,2 +206,181 @@ d1.equals(d1.plusDays(1)); // false

### Converting from and to other temporals
```javascript
// obtain a LocalDate from a LocalDateTime instance
LocalDate.from(LocalDateTime.now()); // current LocalDate e.g. 2016-02-25
LocalDateTime.now().toLocalDate(); // same
var d1 = LocalDate.parse('2016-02-25');
// obtain a LocalDateTime at a certain LocalTime
d1.atStartOfDay(); // '2016-02-25T00:00'
d1.atTime(LocalTime.of(11, 55)); // '2016-02-25T11:55'
d1.atTime(LocalTime.NOON); // '2016-02-25T12:00'
// TODO milestone 1
// add Basic ZoneDateTime and add a Converterhelper
// obtain a LocalDate from an Instant
// Instant.now().atZone(ZoneId.systemDefault()).toLocalDate()
// obtain a LocalDate from a JavaScript Date
// var javascriptDate = new Date();
// Instant.ofEpochMilli(javascriptDate.getTime()).atZone(ZoneId.systemDefault()).toLocalDate()
// obtaim a LocalDate from a moment
// var moment = moment();
// Instant.ofEpochMilli(moment.toDate().getTime()).atZone(ZoneId.systemDefault()).toLocalDate()
```
## LocalTime
A LocalTime represents A time without time-zone in the ISO-8601 calendar system such as '10:15:30'
### Create a LocalTime instance
```javascript
// obtain the current time in the system default timezone, e.g. '10:29:05.743'
LocalTime.now();
// obtain the current time in the utc timezone, e.g. '09:29:05.743'
LocalTime.now(Clock.systemUTC());
// obtain an instance of LocalTime from an ISO8601 formatted text string
LocalTime.parse('09:42'); // '09:42'
LocalTime.parse('09:42:42'); // '09:42:42'
LocalTime.parse('09:42:42.123'); // '09:42:42.123'
LocalTime.parse('09:42:42.123456789'); // '09:42:42.123456789'
// obtain an instance of LocalDate from a hour, minute, second and nano value
LocalTime.of(23, 55) // '23:55'
LocalTime.of(23, 55, 42) // '23:55:42'
LocalTime.of(23, 55, 42, 123000000) // '23:55:42.123'
// obtain an instance of LoclTome from second of day
LocalTime.ofSecondOfDay(3666) // '01:01:06'
```
### Get values from LocalTime
```javascript
var t = LocalTime.parse('23:55:42.123');
t.toString(); // '23:55:42.123' ISO8601 format
t.hour(); // 23
t.minute(); // 55
t.second(); // 42
t.nano(); // 123000000
// get other time based fields
t.get(ChronoField.SECOND_OF_DAY); // 86142
t.get(ChronoField.MILLI_OF_SECOND); // 123
t.get(ChronoField.HOUR_OF_AMPM); // 11
// any other time based ChronoField is allowed as param for get
```
### Adding to/ subtracting from a LocalTime instance
```javascript
var t = LocalTime.parse('11:55:42')
// add/ subtract 12 hours
t.plusHours(12); // '23:55:42'
t.minusHours(12); // '23:55:42'
// add/ subtract 30 minutes
t.plusMinutes(30); // '12:25:42'
t.minusMinutes(30); // '11:25:42'
// add/ subtract 30 minutes
t.plusSeconds(30); // '11:56:12'
t.minusSeconds(30); // '11:55:12'
// add/ subtract 1.000.000 nanos (1 milli second)
t.plusNanos(1000000); // '11:56:42.001'
t.minusNanos(1000000); // '11:55:41.999'
// add/ subtract a time based unit
t.plus(1, ChronoUnit.MILLIS); // '11:55:42.001'
t.plus(1, ChronoUnit.HALF_DAYS); // '23:55:42'
// add/ subtract a duration of 15 minutes
t.plus(Duration.ofMinutes(15)); // '12:10:42'
t.minus(Duration.ofMinutes(15)); // '11:40:42'
```
### Alter certain fields of a LocalTime instance
```javascript
var t = LocalTime.parse('11:55:42')
// set the hour of day to 1
t.withHour(1); // '01:55:42'
// set the minute of hour to 1
t.withMinute(1); // '11:01:42'
// set the second of minute to 1
t.withSecond(1); // '11:55:01'
// set the MILLI_OF_SECOND to 51
t.with(ChronoField.MILLI_OF_SECOND, 51) // '11:55:42.051'
// set by a custom TemporalAdjusters
// sample of a custom adjuster that adjust to the next even second
nextEvenSecond = { adjustInto: function(t){ return t.second() % 2 === 0 ? t.plusSeconds(2) : t.plusSeconds(1); } }
t.with(nextEvenSecond) // '11:55:44'
t.plusSeconds(1).with(nextEvenSecond) // '11:55:44'
```
### Compare LocalTime instances
```javascript
var t1 = LocalTime.parse('11:55:42')
var t2 = t1.plusHours(2);
t1.isAfter(t2); // false
t1.isBefore(t2); // true
t1.equals(t1.plusHours(0)); // true
t1.equals(t1.plusHours(1)); // false
t1.compareTo(t1) === 0; // true
t1.compareTo(t2) < 0; // true
t2.compareTo(t1) > 0; // true
t1.hashCode(); // 916974646
t2.hashCode(); // -1743180648
t1.hashCode() !== t2.hashCode(); // true
```
### Distance between times
```javascript
var t1 = LocalTime.parse('11:00')
var t2 = t1.plusHours(2).plusMinutes(42).plusSeconds(12);
// obtain the duration between the two dates
t1.until(t2, ChronoUnit.HOURS); // 2
t1.until(t2, ChronoUnit.MINUTES); // 162
t1.until(t2, ChronoUnit.SECONDS); // 9732
```

2

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

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

@@ -10,6 +10,2 @@ Immutable data and time library for javascript

**js-joda is a project that wants to bring JSR-310 (more specifically the ThreeTen-Backport) date and time API to the javascript world.
The Project is in a very early state.
Be aware that the most of the things written here are not ready yet**
js-joda, a port of the ThreeTen immutable data and time library to javascript.

@@ -16,0 +12,0 @@ It provides a simple and clean API based on the ISO8601 calendar.

@@ -10,3 +10,3 @@ /*

import {TemporalQueries} from '../temporal/TemporalQueries';
import {TemporalAccessor} from '../temporal/TemporalAccessor';
import {Temporal} from '../temporal/Temporal';

@@ -176,3 +176,3 @@ import {LocalDate} from '../LocalDate';

*/
export class ChronoLocalDate extends TemporalAccessor {
export class ChronoLocalDate extends Temporal {

@@ -179,0 +179,0 @@ isSupported(fieldOrUnit) {

@@ -12,3 +12,3 @@ /*

import {ChronoUnit} from '../temporal/ChronoUnit';
import {TemporalAccessor} from '../temporal/TemporalAccessor';
import {Temporal} from '../temporal/Temporal';
import {TemporalQueries} from '../temporal/TemporalQueries';

@@ -48,3 +48,3 @@

*/
export class ChronoLocalDateTime extends TemporalAccessor {
export class ChronoLocalDateTime extends Temporal {
/* <D extends ChronoLocalDate>

@@ -51,0 +51,0 @@ extends DefaultInterfaceTemporal

@@ -172,3 +172,3 @@ /**

var offsetInMinutes = new Date().getTimezoneOffset(instant.epochMilli());
return ZoneOffset.ofTotalMinutes(offsetInMinutes);
return ZoneOffset.ofTotalMinutes(offsetInMinutes * -1);
}

@@ -175,0 +175,0 @@

@@ -15,3 +15,3 @@ /*

import {ChronoUnit} from './temporal/ChronoUnit';
import {TemporalAccessor} from './temporal/TemporalAccessor';
import {Temporal} from './temporal/Temporal';
import {TemporalQueries} from './temporal/TemporalQueries';

@@ -32,3 +32,3 @@ import {createTemporalQuery} from './temporal/TemporalQuery';

*/
export class DayOfWeek extends TemporalAccessor {
export class DayOfWeek extends Temporal {

@@ -35,0 +35,0 @@ constructor(ordinal, name){

@@ -17,3 +17,3 @@ /*

import {ChronoField} from '../temporal/ChronoField';
import {TemporalAccessor} from '../temporal/TemporalAccessor';
import {Temporal} from '../temporal/Temporal';
import {TemporalQueries} from '../temporal/TemporalQueries';

@@ -43,3 +43,3 @@

*/
export class DateTimeBuilder extends TemporalAccessor {
export class DateTimeBuilder extends Temporal {
constructor(){

@@ -46,0 +46,0 @@ super();

@@ -13,3 +13,3 @@ /*

import {IsoChronology} from '../chrono/IsoChronology';
import {TemporalAccessor} from '../temporal/TemporalAccessor';
import {Temporal} from '../temporal/Temporal';
import {TemporalQueries} from '../temporal/TemporalQueries';

@@ -189,3 +189,3 @@

class Parsed extends TemporalAccessor {
class Parsed extends Temporal {
constructor(dateTimeParseContext){

@@ -192,0 +192,0 @@ super();

@@ -12,3 +12,3 @@ /**

import {MathUtil} from './MathUtil';
import {TemporalAccessor} from './temporal/TemporalAccessor';
import {Temporal} from './temporal/Temporal';

@@ -120,3 +120,3 @@ const NANOS_PER_MILLI = 1000000;

*/
export class Instant extends TemporalAccessor {
export class Instant extends Temporal {

@@ -123,0 +123,0 @@ constructor(seconds, nanoOfSecond){

@@ -19,3 +19,3 @@ /**

import {ChronoUnit} from './temporal/ChronoUnit';
import {TemporalAccessor} from './temporal/TemporalAccessor';
import {Temporal} from './temporal/Temporal';
import {TemporalQueries} from './temporal/TemporalQueries';

@@ -111,3 +111,3 @@ import {createTemporalQuery} from './temporal/TemporalQuery';

*/
export class LocalTime extends TemporalAccessor /** implements Temporal, TemporalAdjuster */ {
export class LocalTime extends Temporal /** implements Temporal, TemporalAdjuster */ {
/**

@@ -410,7 +410,7 @@ * Obtains the current time from the specified clock.

case ChronoField.MINUTE_OF_DAY: return this._hour * 60 + this._minute;
case ChronoField.HOUR_OF_AMPM: return this._hour % 12;
case ChronoField.HOUR_OF_AMPM: return MathUtil.intMod(this._hour, 12);
case ChronoField.CLOCK_HOUR_OF_AMPM: var ham = MathUtil.intMod(this._hour, 12); return (ham % 12 === 0 ? 12 : ham);
case ChronoField.HOUR_OF_DAY: return this._hour;
case ChronoField.CLOCK_HOUR_OF_DAY: return (this._hour === 0 ? 24 : this._hour);
case ChronoField.AMPM_OF_DAY: return this._hour / 12;
case ChronoField.AMPM_OF_DAY: return MathUtil.intDiv(this._hour, 12);
}

@@ -1348,3 +1348,3 @@ throw new UnsupportedTemporalTypeException('Unsupported field: ' + field);

var localTime = Object.create(LocalTime.prototype);
TemporalAccessor.call(localTime);
Temporal.call(localTime);
localTime._hour = hour;

@@ -1351,0 +1351,0 @@ localTime._minute = minute;

@@ -11,3 +11,3 @@ /**

import {IsoChronology} from './chrono/IsoChronology';
import {TemporalAccessor} from './temporal/TemporalAccessor';
import {Temporal} from './temporal/Temporal';
import {TemporalQueries} from './temporal/TemporalQueries';

@@ -37,3 +37,3 @@

*/
export class Month extends TemporalAccessor {
export class Month extends Temporal {

@@ -40,0 +40,0 @@ /**

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc