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 1.0.2 to 1.1.0

.eslintrc.js

6

benchmark/package.json

@@ -11,3 +11,3 @@ {

"type": "git",
"url": "git+https://github.com/pithu/js-joda.git"
"url": "git+https://github.com/js-joda/js-joda.git"
},

@@ -17,5 +17,5 @@ "author": "",

"bugs": {
"url": "https://github.com/pithu/js-joda/issues"
"url": "https://github.com/js-joda/js-joda/issues"
},
"homepage": "https://github.com/pithu/js-joda#readme",
"homepage": "https://github.com/js-joda/js-joda#readme",
"dependencies": {

@@ -22,0 +22,0 @@ "benchmark": "^2.1.0",

@@ -14,3 +14,3 @@ {

],
"homepage": "https://github.com/pithu/joda-js",
"homepage": "https://github.com/js-joda/joda-js",
"ignore": [

@@ -17,0 +17,0 @@ "**/.*",

js-joda Cheat sheet
=============================================
[For a detailed API Reference refer to the ESDoc generated docs](https://doc.esdoc.org/github.com/pithu/js-joda/)
[For a detailed API Reference refer to the ESDoc generated docs](https://doc.esdoc.org/github.com/js-joda/js-joda/)

@@ -57,3 +57,3 @@ ## Table of content

Tip: Try out the cheat sheet examples in your browser console. All js-joda classes are imported into the global name space of [this webpage](http://pithu.github.io/js-joda/cheat-sheet.html).
Tip: Try out the cheat sheet examples in your browser console. All js-joda classes are imported into the global name space of [the js-joda webpage](http://js-joda.github.io/js-joda/cheat-sheet.html).

@@ -60,0 +60,0 @@ ## Consistent method prefixes

{
"name": "js-joda",
"version": "1.0.2",
"version": "1.1.0",
"description": "a date and time library for javascript",
"repository": {
"type": "git",
"url": "https://github.com/pithu/js-joda.git"
"url": "https://github.com/js-joda/js-joda.git"
},

@@ -19,3 +19,4 @@ "main": "dist/js-joda.js",

"build-dist": "./node_modules/.bin/webpack --progress --colors --bail && DIST_MIN=1 ./node_modules/.bin/webpack --progress --colors --bail",
"build-md-toc": "./node_modules/.bin/markdown-toc -i CheatSheet.md"
"build-md-toc": "./node_modules/.bin/markdown-toc -i CheatSheet.md",
"build-gz-check": "gzip -kf dist/js-joda.min.js && ls -al ./dist/js-joda.min.js*"
},

@@ -28,6 +29,6 @@ "keywords": [

"author": "pithu",
"homepage": "https://pithu.github.com/js-joda",
"homepage": "https://js-joda.github.com/js-joda",
"devDependencies": {
"babel-cli": "^6.6.5",
"babel-core": "^6.7.0",
"babel-core": "^6.7.4",
"babel-loader": "^6.2.4",

@@ -39,6 +40,10 @@ "babel-preset-es2015": "^6.6.0",

"esdoc": "^0.4.6",
"eslint": "^2.4.0",
"eslint-config-standard": "^5.1.0",
"eslint-plugin-promise": "^1.1.0",
"eslint-plugin-standard": "^1.3.2",
"isparta": "^4.0.0",
"karma": "^0.13.22",
"karma-chai-plugins": "^0.7.0",
"karma-chrome-launcher": "^0.2.2",
"karma-chrome-launcher": "^0.2.3",
"karma-firefox-launcher": "^0.1.7",

@@ -49,5 +54,5 @@ "karma-mocha": "^0.2.2",

"karma-webpack": "^1.7.0",
"markdown-toc": "^0.12.3",
"markdown-toc": "^0.12.5",
"mocha": "^2.4.5",
"phantomjs": "^2.1.3",
"phantomjs-prebuilt": "^2.1.6",
"webpack": "^1.12.14"

@@ -54,0 +59,0 @@ },

@@ -1,13 +0,13 @@

Immutable data and time library for javascript
=============================================
Immutable date and time library for javascript
==============================================
[![npm version](https://badge.fury.io/js/js-joda.svg)](https://badge.fury.io/js/js-joda)
[![Build Status](https://travis-ci.org/pithu/js-joda.svg)](https://travis-ci.org/pithu/js-joda)
[![Coverage Status](https://coveralls.io/repos/pithu/js-joda/badge.svg?branch=master&service=github)](https://coveralls.io/github/pithu/js-joda?branch=master)
[![Build Status](https://travis-ci.org/js-joda/js-joda.svg)](https://travis-ci.org/js-joda/js-joda)
[![Coverage Status](https://coveralls.io/repos/js-joda/js-joda/badge.svg?branch=master&service=github)](https://coveralls.io/github/js-joda/js-joda?branch=master)
## Introduction
+ **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** is an **immutable date 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 has a lightweight footprint, only **43 kB minified and compressed**, no third party dependencies.

@@ -20,3 +20,3 @@ + js-joda is **fast**. It is about 2 to 10 times faster than other javascript date libraries.

+ js-joda is **robust and stable**. We ported more then 1500 test-cases with a lots of test-permutations from the threetenbp project.
+ js-joda is **robust and stable**. We ported more then 1700 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.

@@ -38,4 +38,6 @@

## The js-joda domain models
## The threeten domain models
### Dates and Times
+ **LocalDate** represents a date without a time and time-zone in the ISO-8601 calendar system, such as 2007-12-24.

@@ -51,2 +53,4 @@

### Duration and Period
+ **Duration** is a time-based amount of time, such as '34.5 seconds'.

@@ -56,2 +60,14 @@

### Additional value types
+ **Year** represents a year in the ISO-8601 calendar system, such as '2016'.
+ **YearMonth** represents a year and a month in the ISO-8601 calendar system, such as '2016-01'.
+ **Month** represents a month-of-year in the ISO-8601 calendar system, such as 'July'.
+ **MonthDay** represents a month-day in the ISO-8601 calendar system, such as '--12-03'. Could be used to represent e.g. Birthdays.
+ **DayOfWeek** represents a day-of-week in the ISO-8601 calendar system, such as 'Tuesday'.
## Getting started

@@ -86,4 +102,4 @@

+ [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
+ [js-joda Homepage](http://pithu.github.io/js-joda/) Project homepage
+ [API](https://doc.esdoc.org/github.com/js-joda/js-joda/) ESDoc generated API documentation hosted by the ESDoc Hosting Service
+ [js-joda Homepage](http://js-joda.github.io/js-joda/) Project homepage

@@ -90,0 +106,0 @@ ## Roadmap

@@ -14,4 +14,7 @@ /*

import {_init as MonthInit} from './Month';
import {_init as MonthDayInit} from './MonthDay';
import {_init as PeriodInit} from './Period';
import {_init as YearInit} from './Year';
import {_init as YearConstantsInit} from './YearConstants';
import {_init as YearMonthInit} from './YearMonth';
import {_init as ZonedDateTimeInit} from './ZonedDateTime';

@@ -23,2 +26,3 @@ import {_init as IsoChronologyInit} from './chrono/IsoChronology';

import {_init as IsoFieldsInit} from './temporal/IsoFields';
import {_init as DateTimeFormatterBuilderInit} from './format/DateTimeFormatterBuilder';

@@ -38,3 +42,3 @@ import {_init as TemporalQueriesInit} from './temporal/TemporalQueriesFactory';

YearInit();
YearConstantsInit();
DurationInit();

@@ -50,3 +54,6 @@ LocalTimeInit();

LocalDateTimeInit();
YearInit();
MonthInit();
YearMonthInit();
MonthDayInit();
PeriodInit();

@@ -58,4 +65,5 @@ ZoneOffsetInit();

DateTimeFormatterInit();
DateTimeFormatterBuilderInit();
}
init();

@@ -26,3 +26,3 @@ /**

if (!(value instanceof _class)) {
throw new IllegalArgumentException(parameterName + ' must be an instance of ' + (_class.name ? _class.name : _class));
throw new IllegalArgumentException(parameterName + ' must be an instance of ' + (_class.name ? _class.name : _class) + (value && value.constructor && value.constructor.name ? ', but is ' + value.constructor.name : ''));
}

@@ -29,0 +29,0 @@ return value;

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

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

@@ -380,2 +380,3 @@ import {DateTimeFormatterBuilder} from './format/DateTimeFormatterBuilder';

adjustInto(temporal) {
requireNonNull(temporal, 'temporal');
return temporal.with(ChronoField.DAY_OF_WEEK, this.value());

@@ -382,0 +383,0 @@ }

@@ -47,4 +47,3 @@ /**

*/
export class Duration extends TemporalAmount
/*implements TemporalAmount, Comparable<Duration>, Serializable */ {
export class Duration extends TemporalAmount /*implements TemporalAmount, Comparable<Duration>, Serializable */ {

@@ -378,3 +377,4 @@ /**

/**
* to handle function overriding this function accepts any number of arguments, checks their type and delegates to the appropriate function
* to handle function overriding this function accepts any number of arguments, checks their type and delegates to the appropriate
* function
*

@@ -547,26 +547,29 @@ * @return {Duration}

plusDuration(duration) {
requireNonNull(duration, 'duration');
return this.plus(duration.seconds(), duration.nano());
}
/**
* to handle function overriding this function accepts two arguments, checks their type and delegates to the appropriate function
*
* @param {!(Duration|number)} a
* @param {ChronoUnit|number} b
* @return {Duration}
* function overloading for {@link Duration.of}
*
* if called with 1 arguments, then {@link Duration.plusDuration} is executed.
*
* if called with 2 arguments and second argument is an instance of ChronoUnit, then {@link Duration.plusAmountUnit} is executed.
*
* Otherwise {@link Duration.plusSecondsNanos} is executed.
*
* @param {!(Duration|number)} arg1
* @param {ChronoUnit|number} arg2
* @returns {Duration}
*/
plus(a, b){
if (a instanceof Duration) {
requireNonNull(a, 'duration');
return this.plusDuration(a);
plus() {
if (arguments.length === 1) {
return this.plusDuration.apply(this, arguments);
}
if (b instanceof ChronoUnit) {
requireNonNull(a, 'amount');
requireNonNull(b, 'unit');
return this.plusAmountUnit(a, b);
else if (arguments.length === 2 && arguments[1] instanceof ChronoUnit) {
return this.plusAmountUnit.apply(this, arguments);
} else {
return this.plusSecondsNanos.apply(this, arguments);
}
requireNonNull(a, 'seconds');
requireNonNull(b, 'nanos');
return this.plusSecondsNanos(a, b);
}

@@ -591,2 +594,3 @@

plusAmountUnit(amountToAdd, unit) {
requireNonNull(amountToAdd, 'amountToAdd');
requireNonNull(unit, 'unit');

@@ -705,2 +709,4 @@ if (unit === ChronoUnit.DAYS) {

plusSecondsNanos(secondsToAdd, nanosToAdd) {
requireNonNull(secondsToAdd, 'secondsToAdd');
requireNonNull(nanosToAdd, 'nanosToAdd');
if ((secondsToAdd | nanosToAdd) === 0) {

@@ -718,21 +724,18 @@ return this;

/**
* to handle function overriding this function accepts two arguments, checks their type and delegates to the appropriate function
* function overloading for {@link Duration.minus}
*
* @param {!(Duration|number)} a
* @param {ChronoUnit|number} b
* if called with 1 arguments and first argument is an instance of Duration, then {@link Duration.minusDuration} is executed.
*
* Otherwise {@link Duration.minusAmountUnit} is executed.
*
* @param {!(Duration|number)} arg1
* @param {ChronoUnit} arg2
* @return {Duration}
*/
minus(a, b) {
if (a instanceof Duration) {
requireNonNull(a, 'duration');
return this.minusDuration(a);
minus() {
if (arguments.length === 1) {
return this.minusDuration.apply(this, arguments);
} else {
return this.minusAmountUnit.apply(this, arguments);
}
if (b instanceof ChronoUnit) {
requireNonNull(a, 'amount');
requireNonNull(b, 'unit');
return this.minusAmountUnit(a, b);
}
requireNonNull(a, 'seconds');
requireNonNull(b, 'nanos');
return this.minusSecondsNanos(a, b);
}

@@ -750,2 +753,3 @@

minusDuration(duration) {
requireNonNull(duration, 'duration');
var secsToSubtract = duration.seconds();

@@ -775,2 +779,4 @@ var nanosToSubtract = duration.nano();

minusAmountUnit(amountToSubtract, unit) {
requireNonNull(amountToSubtract, 'amountToSubtract');
requireNonNull(unit, 'unit');
return (amountToSubtract === MIN_SAFE_INTEGER ? this.plusAmountUnit(MAX_SAFE_INTEGER, unit).plus(1, unit) : this.plusAmountUnit(-amountToSubtract, unit));

@@ -777,0 +783,0 @@ }

@@ -46,2 +46,8 @@ /**

this.message = msg;
this.parsedString = () => {
return text;
};
this.errorIndex = () => {
return index;
};
}

@@ -118,2 +118,139 @@ /**

/**
* Creates a formatter using the specified pattern.
* <p>
* This method will create a formatter based on a simple pattern of letters and symbols.
* For example, {@code d MMM yyyy} will format 2011-12-03 as '3 Dec 2011'.
* <p>
* The returned formatter will use the default locale, but this can be changed
* using {@link DateTimeFormatter#withLocale(Locale)}.
* <p>
* All letters 'A' to 'Z' and 'a' to 'z' are reserved as pattern letters.
* The following pattern letters are defined:
* <pre>
* Symbol Meaning Presentation Examples
* ------ ------- ------------ -------
* G era number/text 1; 01; AD; Anno Domini
* y year year 2004; 04
* D day-of-year number 189
* M month-of-year number/text 7; 07; Jul; July; J
* d day-of-month number 10
*
* Q quarter-of-year number/text 3; 03; Q3
* Y week-based-year year 1996; 96
* w week-of-year number 27
* W week-of-month number 27
* e localized day-of-week number 2; Tue; Tuesday; T
* E day-of-week number/text 2; Tue; Tuesday; T
* F week-of-month number 3
*
* a am-pm-of-day text PM
* h clock-hour-of-am-pm (1-12) number 12
* K hour-of-am-pm (0-11) number 0
* k clock-hour-of-am-pm (1-24) number 0
*
* H hour-of-day (0-23) number 0
* m minute-of-hour number 30
* s second-of-minute number 55
* S fraction-of-second fraction 978
* A milli-of-day number 1234
* n nano-of-second number 987654321
* N nano-of-day number 1234000000
*
* V time-zone ID zone-id America/Los_Angeles; Z; -08:30
* z time-zone name zone-name Pacific Standard Time; PST
* X zone-offset 'Z' for zero offset-X Z; -08; -0830; -08:30; -083015; -08:30:15;
* x zone-offset offset-x +0000; -08; -0830; -08:30; -083015; -08:30:15;
* Z zone-offset offset-Z +0000; -0800; -08:00;
*
* p pad next pad modifier 1
*
* ' escape for text delimiter
* '' single quote literal '
* [ optional section start
* ] optional section end
* {} reserved for future use
* </pre>
* <p>
* The count of pattern letters determine the format.
* <p>
* <b>Text</b>: The text style is determined based on the number of pattern letters used.
* Less than 4 pattern letters will use the {@link TextStyle#SHORT short form}.
* Exactly 4 pattern letters will use the {@link TextStyle#FULL full form}.
* Exactly 5 pattern letters will use the {@link TextStyle#NARROW narrow form}.
* <p>
* <b>Number</b>: If the count of letters is one, then the value is printed using the minimum number
* of digits and without padding as per {@link DateTimeFormatterBuilder#appendValue(TemporalField)}.
* Otherwise, the count of digits is used as the width of the output field as per
* {@link DateTimeFormatterBuilder#appendValue(TemporalField, int)}.
* <p>
* <b>Number/Text</b>: If the count of pattern letters is 3 or greater, use the Text rules above.
* Otherwise use the Number rules above.
* <p>
* <b>Fraction</b>: Outputs the nano-of-second field as a fraction-of-second.
* The nano-of-second value has nine digits, thus the count of pattern letters is from 1 to 9.
* If it is less than 9, then the nano-of-second value is truncated, with only the most
* significant digits being output.
* When parsing in strict mode, the number of parsed digits must match the count of pattern letters.
* When parsing in lenient mode, the number of parsed digits must be at least the count of pattern
* letters, up to 9 digits.
* <p>
* <b>Year</b>: The count of letters determines the minimum field width below which padding is used.
* If the count of letters is two, then a {@link DateTimeFormatterBuilder#appendValueReduced reduced}
* two digit form is used.
* For printing, this outputs the rightmost two digits. For parsing, this will parse using the
* base value of 2000, resulting in a year within the range 2000 to 2099 inclusive.
* If the count of letters is less than four (but not two), then the sign is only output for negative
* years as per {@link SignStyle#NORMAL}.
* Otherwise, the sign is output if the pad width is exceeded, as per {@link SignStyle#EXCEEDS_PAD}
* <p>
* <b>ZoneId</b>: This outputs the time-zone ID, such as 'Europe/Paris'.
* If the count of letters is two, then the time-zone ID is output.
* Any other count of letters throws {@code IllegalArgumentException}.
* <p>
* <b>Zone names</b>: This outputs the display name of the time-zone ID.
* If the count of letters is one, two or three, then the short name is output.
* If the count of letters is four, then the full name is output.
* Five or more letters throws {@code IllegalArgumentException}.
* <p>
* <b>Offset X and x</b>: This formats the offset based on the number of pattern letters.
* One letter outputs just the hour', such as '+01', unless the minute is non-zero
* in which case the minute is also output, such as '+0130'.
* Two letters outputs the hour and minute, without a colon, such as '+0130'.
* Three letters outputs the hour and minute, with a colon, such as '+01:30'.
* Four letters outputs the hour and minute and optional second, without a colon, such as '+013015'.
* Five letters outputs the hour and minute and optional second, with a colon, such as '+01:30:15'.
* Six or more letters throws {@code IllegalArgumentException}.
* Pattern letter 'X' (upper case) will output 'Z' when the offset to be output would be zero,
* whereas pattern letter 'x' (lower case) will output '+00', '+0000', or '+00:00'.
* <p>
* <b>Offset Z</b>: This formats the offset based on the number of pattern letters.
* One, two or three letters outputs the hour and minute, without a colon, such as '+0130'.
* Four or more letters throws {@code IllegalArgumentException}.
* The output will be '+0000' when the offset is zero.
* <p>
* <b>Optional section</b>: The optional section markers work exactly like calling
* {@link DateTimeFormatterBuilder#optionalStart()} and {@link DateTimeFormatterBuilder#optionalEnd()}.
* <p>
* <b>Pad modifier</b>: Modifies the pattern that immediately follows to be padded with spaces.
* The pad width is determined by the number of pattern letters.
* This is the same as calling {@link DateTimeFormatterBuilder#padNext(int)}.
* <p>
* For example, 'ppH' outputs the hour-of-day padded on the left with spaces to a width of 2.
* <p>
* Any unrecognized letter is an error.
* Any non-letter character, other than '[', ']', '{', '}' and the single quote will be output directly.
* Despite this, it is recommended to use single quotes around all characters that you want to
* output directly to ensure that future changes do not break your application.
*
* @param {String} pattern the pattern to use, not null
* @return {DateTimeFormatter} the formatter based on the pattern, not null
* @throws IllegalArgumentException if the pattern is invalid
* @see DateTimeFormatterBuilder#appendPattern(String)
*/
static ofPattern(pattern) {
return new DateTimeFormatterBuilder().appendPattern(pattern).toFormatter();
}
//-----------------------------------------------------------------------

@@ -218,39 +355,39 @@ /**

//-----------------------------------------------------------------------
/**
* Formats a date-time object using this formatter.
* <p>
* This formats the date-time to a String using the rules of the formatter.
*
* @param {TemporalAccessor} temporal the temporal object to print, not null
* @return {String} the printed string, not null
* @throws DateTimeException if an error occurs during formatting
*/
format(temporal) {
var buf = new StringBuilder(32);
this._formatTo(temporal, buf);
return buf.toString();
}
/**
* Formats a date-time object using this formatter.
* <p>
* This formats the date-time to a String using the rules of the formatter.
*
* @param {TemporalAccessor} temporal the temporal object to print, not null
* @return {String} the printed string, not null
* @throws DateTimeException if an error occurs during formatting
*/
format(temporal) {
var buf = new StringBuilder(32);
this._formatTo(temporal, buf);
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* Formats a date-time object to an {@code Appendable} using this formatter.
* <p>
* This formats the date-time to the specified destination.
* {@link Appendable} is a general purpose interface that is implemented by all
* key character output classes including {@code StringBuffer}, {@code StringBuilder},
* {@code PrintStream} and {@code Writer}.
* <p>
* Although {@code Appendable} methods throw an {@code IOException}, this method does not.
* Instead, any {@code IOException} is wrapped in a runtime exception.
*
* @param {TemporalAccessor} temporal - the temporal object to print, not null
* @param {StringBuilder} appendable - the appendable to print to, not null
* @throws DateTimeException if an error occurs during formatting
*/
_formatTo(temporal, appendable) {
requireNonNull(temporal, 'temporal');
requireNonNull(appendable, 'appendable');
var context = new DateTimePrintContext(temporal, this);
this._printerParser.print(context, appendable);
}
//-----------------------------------------------------------------------
/**
* Formats a date-time object to an {@code Appendable} using this formatter.
* <p>
* This formats the date-time to the specified destination.
* {@link Appendable} is a general purpose interface that is implemented by all
* key character output classes including {@code StringBuffer}, {@code StringBuilder},
* {@code PrintStream} and {@code Writer}.
* <p>
* Although {@code Appendable} methods throw an {@code IOException}, this method does not.
* Instead, any {@code IOException} is wrapped in a runtime exception.
*
* @param {TemporalAccessor} temporal - the temporal object to print, not null
* @param {StringBuilder} appendable - the appendable to print to, not null
* @throws DateTimeException if an error occurs during formatting
*/
_formatTo(temporal, appendable) {
requireNonNull(temporal, 'temporal');
requireNonNull(appendable, 'appendable');
var context = new DateTimePrintContext(temporal, this);
this._printerParser.print(context, appendable);
}

@@ -257,0 +394,0 @@ /**

@@ -15,4 +15,6 @@ /**

export { Month } from './Month';
export { MonthDay } from './MonthDay';
export { Period } from './Period';
export { Year } from './Year';
export { YearMonth } from './YearMonth';
export { ZonedDateTime } from './ZonedDateTime';

@@ -19,0 +21,0 @@ export { ZoneOffset } from './ZoneOffset';

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

import {DateTimeException, UnsupportedTemporalTypeException} from './errors';
import {DateTimeFormatterBuilder} from './format/DateTimeFormatterBuilder';
import {IsoChronology} from './chrono/IsoChronology';

@@ -60,2 +61,20 @@ import {Temporal} from './temporal/Temporal';

/**
* Gets the textual representation, such as 'Jan' or 'December'.
* <p>
* This returns the textual name used to identify the month-of-year.
* The parameters control the length of the returned text and the locale.
* <p>
* If no textual mapping is found then the {@link #getValue() numeric value} is returned.
*
* @param {TextStyle} style - the length of the text required, not null
* @param {Locale} locale - the locale to use, not null
* @return {string} the text value of the day-of-week, not null
*/
getDisplayName(style, locale) {
// TODO:
throw new IllegalArgumentException('Pattern using (localized) text not implemented yet!');
return new DateTimeFormatterBuilder().appendText(ChronoField.MONTH_OF_YEAR, style).toFormatter(locale).format(this);
}
/**
* Checks if the specified field is supported.

@@ -460,2 +479,36 @@ * <p>

}
/**
* Obtains an instance of {@code Month} from a temporal object.
* <p>
* This obtains a month based on the specified temporal.
* A {@code TemporalAccessor} represents an arbitrary set of date and time information,
* which this factory converts to an instance of {@code Month}.
* <p>
* The conversion extracts the {@link ChronoField#MONTH_OF_YEAR MONTH_OF_YEAR} field.
* The extraction is only permitted if the temporal object has an ISO
* chronology, or can be converted to a {@code LocalDate}.
* <p>
* This method matches the signature of the functional interface {@link TemporalQuery}
* allowing it to be used in queries via method reference, {@code Month::from}.
*
* @param {TemporalAccessor} temporal the temporal object to convert, not null
* @return {Month} the month-of-year, not null
* @throws DateTimeException if unable to convert to a {@code Month}
*/
static from(temporal) {
if (temporal instanceof Month) {
return temporal;
}
try {
/* only ISO for now
if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) {
temporal = LocalDate.from(temporal);
}*/
return Month.of(temporal.get(ChronoField.MONTH_OF_YEAR));
} catch (ex) {
throw new DateTimeException('Unable to obtain Month from TemporalAccessor: ' +
temporal + ' of type ' + (temporal && temporal.constructor != null ? temporal.constructor.name : ''), ex);
}
}
}

@@ -462,0 +515,0 @@

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

import {ValueRange} from './ValueRange';
import {Year} from '../Year';
import {YearConstants} from '../YearConstants';

@@ -325,3 +325,3 @@ /**

ChronoField.EPOCH_DAY = new ChronoField('EpochDay', ChronoUnit.DAYS, ChronoUnit.FOREVER, ValueRange.of(Math.floor(Year.MIN_VALUE * 365.25), Math.floor(Year.MAX_VALUE * 365.25)));
ChronoField.EPOCH_DAY = new ChronoField('EpochDay', ChronoUnit.DAYS, ChronoUnit.FOREVER, ValueRange.of(Math.floor(YearConstants.MIN_VALUE * 365.25), Math.floor(YearConstants.MAX_VALUE * 365.25)));

@@ -334,7 +334,7 @@ ChronoField.ALIGNED_WEEK_OF_MONTH = new ChronoField('AlignedWeekOfMonth', ChronoUnit.WEEKS, ChronoUnit.MONTHS, ValueRange.of(1, 4, 5));

ChronoField.PROLEPTIC_MONTH = new ChronoField('ProlepticMonth', ChronoUnit.MONTHS, ChronoUnit.FOREVER, ValueRange.of(Year.MIN_VALUE * 12, Year.MAX_VALUE * 12 + 11));
ChronoField.PROLEPTIC_MONTH = new ChronoField('ProlepticMonth', ChronoUnit.MONTHS, ChronoUnit.FOREVER, ValueRange.of(YearConstants.MIN_VALUE * 12, YearConstants.MAX_VALUE * 12 + 11));
ChronoField.YEAR_OF_ERA = new ChronoField('YearOfEra', ChronoUnit.YEARS, ChronoUnit.FOREVER, ValueRange.of(1, Year.MAX_VALUE, Year.MAX_VALUE + 1));
ChronoField.YEAR_OF_ERA = new ChronoField('YearOfEra', ChronoUnit.YEARS, ChronoUnit.FOREVER, ValueRange.of(1, YearConstants.MAX_VALUE, YearConstants.MAX_VALUE + 1));
ChronoField.YEAR = new ChronoField('Year', ChronoUnit.YEARS, ChronoUnit.FOREVER, ValueRange.of(Year.MIN_VALUE, Year.MAX_VALUE), 'year');
ChronoField.YEAR = new ChronoField('Year', ChronoUnit.YEARS, ChronoUnit.FOREVER, ValueRange.of(YearConstants.MIN_VALUE, YearConstants.MAX_VALUE), 'year');

@@ -341,0 +341,0 @@ ChronoField.ERA = new ChronoField('Era', ChronoUnit.ERAS, ChronoUnit.FOREVER, ValueRange.of(0, 1));

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

import {Duration} from '../Duration';
import {Year} from '../Year';
import {YearConstants} from '../YearConstants';
import {TemporalUnit} from './TemporalUnit';

@@ -458,3 +458,3 @@

*/
ChronoUnit.ERAS = new ChronoUnit('Eras', Duration.ofSeconds(31556952 * (Year.MAX_VALUE + 1)));
ChronoUnit.ERAS = new ChronoUnit('Eras', Duration.ofSeconds(31556952 * (YearConstants.MAX_VALUE + 1)));
/**

@@ -461,0 +461,0 @@ * Artificial unit that represents the concept of forever.

@@ -845,20 +845,21 @@ /*

IsoFields.QUARTER_YEARS = QUARTER_YEARS;
// this differs from threeten, but for ease of use we bring back good old joda time functionality
/**
* the week of the week based year as defined by the ISO8601 Standard with a Monday-based week
*
* @returns {number} the week a the week based year
*/
LocalDate.prototype.isoWeekOfWeekyear = function () {
return this.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
};
/**
* the year of the week based year as defined by the ISO8601 Standard with a Monday-based week
*
* @returns {number} the year a the week based year
*/
LocalDate.prototype.isoWeekyear = function () {
return this.get(IsoFields.WEEK_BASED_YEAR);
};
}
// this differs from threeten, but for ease of use we bring back good old joda time functionality
/**
* the week of the week based year as defined by the ISO8601 Standard with a Monday-based week
*
* @returns {number} the week a the week based year
*/
LocalDate.prototype.isoWeekOfWeekyear = function () {
return this.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
};
/**
* the year of the week based year as defined by the ISO8601 Standard with a Monday-based week
*
* @returns {number} the year a the week based year
*/
LocalDate.prototype.isoWeekyear = function () {
return this.get(IsoFields.WEEK_BASED_YEAR);
};

@@ -56,3 +56,3 @@ /*

} else if(query === TemporalQueries.zone()){
return LocalTime.ofInstant(Instant.ofEpochMilli(this._epochMilli), this._zone);
return this._zone;
}

@@ -88,2 +88,10 @@ return super.query(query);

/**
*
* @param {TemporalField} field
* @returns {boolean}
*/
isSupported(field){
return field === ChronoField.INSTANT_SECONDS || field === ChronoField.NANO_OF_SECOND;
}
}

@@ -90,0 +98,0 @@

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

*/
import {DateTimeException, UnsupportedTemporalTypeException} from './errors';
import {requireNonNull, requireInstance} from './assert';
import {MathUtil} from './MathUtil';
import {ChronoField} from './temporal/ChronoField';
import {ChronoUnit} from './temporal/ChronoUnit';
import {Clock} from './Clock';
import {DateTimeFormatter} from './format/DateTimeFormatter';
import {DateTimeFormatterBuilder} from './format/DateTimeFormatterBuilder';
import {IsoChronology} from './chrono/IsoChronology';
import {LocalDate} from './LocalDate';
import {Month} from './Month';
import {MonthDay} from './MonthDay';
import {SignStyle} from './format/SignStyle';
import {Temporal} from './temporal/Temporal';
import {TemporalAccessor} from './temporal/TemporalAccessor';
import {TemporalAmount} from './temporal/TemporalAmount';
import {TemporalQueries} from './temporal/TemporalQueries';
import {TemporalQuery, createTemporalQuery} from './temporal/TemporalQuery';
import {TemporalUnit} from './temporal/TemporalUnit';
import {ValueRange} from './temporal/ValueRange';
import {YearConstants} from './YearConstants';
import {YearMonth} from './YearMonth';
import {ZoneId} from './ZoneId';
/**

@@ -44,13 +71,760 @@ * A year in the ISO-8601 calendar system, such as {@code 2007}.

*/
export class Year {}
export class Year extends Temporal {
export function _init() {
/**
* The minimum supported year
*
* @param {number} value
*/
Year.MIN_VALUE = -999999;
constructor(value) {
super();
this._year = value;
}
/**
* The maximum supported year
*
* @return {number} gets the value
*/
Year.MAX_VALUE = 999999;
value() {
return this._year;
}
/**
* function overloading for {@link Year.now}
*
* if called without arguments, then {@link Year.now0} is executed.
* if called with 1 arguments and first argument is an instance of ZoneId, then {@link Year.nowZoneId} is executed.
*
* Otherwise {@link Year.nowClock} is executed.
*
* @param {!(ZoneId|Clock|null)} arg1
* @returns {Year}
*/
static now(arg = undefined) {
if (arg === undefined) {
return Year.now0();
} else if (arg instanceof ZoneId) {
return Year.nowZoneId(arg);
} else {
return Year.nowClock(arg);
}
}
/**
* Obtains the current year from the system clock in the default time-zone.
* <p>
* This will query the {@link Clock#systemDefaultZone() system clock} in the default
* time-zone to obtain the current year.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @return {Year} the current year using the system clock and default time-zone, not null
*/
static now0() {
return Year.nowClock(Clock.systemDefaultZone());
}
/**
* Obtains the current year from the system clock in the specified time-zone.
* <p>
* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current year.
* Specifying the time-zone avoids dependence on the default time-zone.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @param {ZoneId} zone the zone ID to use, not null
* @return {Year} the current year using the system clock, not null
*/
static nowZoneId(zone) {
requireNonNull(zone, 'zone');
requireInstance(zone, ZoneId, 'zone');
return Year.nowClock(Clock.system(zone));
}
/**
* Obtains the current year from the specified clock.
* <p>
* This will query the specified clock to obtain the current year.
* 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} clock the clock to use, not null
* @return {Year} the current year, not null
*/
static nowClock(clock) {
requireNonNull(clock, 'clock');
requireInstance(clock, Clock, 'clock');
let now = LocalDate.now(clock); // called once
return Year.of(now.year());
}
/**
* Obtains an instance of {@code Year}.
* <p>
* This method accepts a year value from the proleptic ISO calendar system.
* <p>
* The year 2AD/CE is represented by 2.<br>
* The year 1AD/CE is represented by 1.<br>
* The year 1BC/BCE is represented by 0.<br>
* The year 2BC/BCE is represented by -1.<br>
*
* @param {Number} isoYear the ISO proleptic year to represent, from {@code MIN_VALUE} to {@code MAX_VALUE}
* @return {Year} the year, not null
* @throws DateTimeException if the field is invalid
*/
static of(isoYear) {
requireNonNull(isoYear, 'isoYear');
ChronoField.YEAR.checkValidValue(isoYear);
return new Year(isoYear);
}
//-----------------------------------------------------------------------
/**
* Obtains an instance of {@code Year} from a temporal object.
* <p>
* A {@code TemporalAccessor} represents some form of date and time information.
* This factory converts the arbitrary temporal object to an instance of {@code Year}.
* <p>
* The conversion extracts the {@link ChronoField#YEAR year} field.
* The extraction is only permitted if the temporal object has an ISO
* chronology, or can be converted to a {@code LocalDate}.
* <p>
* This method matches the signature of the functional interface {@link TemporalQuery}
* allowing it to be used in queries via method reference, {@code Year::from}.
*
* @param {TemporalAccessor} temporal the temporal object to convert, not null
* @return {Year} the year, not null
* @throws DateTimeException if unable to convert to a {@code Year}
*/
static from(temporal) {
requireNonNull(temporal, 'temporal');
requireInstance(temporal, TemporalAccessor, 'temporal');
if (temporal instanceof Year) {
return temporal;
}
try {
/* TODO: we support only ISO for now
if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) {
temporal = LocalDate.from(temporal);
}*/
return Year.of(temporal.get(ChronoField.YEAR));
} catch (ex) {
throw new DateTimeException('Unable to obtain Year from TemporalAccessor: ' +
temporal + ', type ' + (temporal && temporal.constructor != null ? temporal.constructor.name : ''));
}
}
//-----------------------------------------------------------------------
/**
* function overloading for {@link Year.parse}
*
* if called with 1 argument, then {@link Year.parseText} is executed.
*
* Otherwise {@link Year.parseTextFormatter} is executed.
*
* @param {!(String)} text
* @param {DateTimeFormatter} formatter
* @returns {Year}
*/
static parse() {
if (arguments.length <= 1) {
return Year.parseText(arguments[0]);
} else {
return Year.parseTextFormatter(arguments[0], arguments[1]);
}
}
/**
* Obtains an instance of {@code Year} from a text string such as {@code 2007}.
* <p>
* The string must represent a valid year.
* Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol.
*
* @param {String} text the text to parse such as "2007", not null
* @return {Year} the parsed year, not null
* @throws DateTimeParseException if the text cannot be parsed
*/
static parseText(text) {
requireNonNull(text, 'text');
return Year.parse(text, PARSER);
}
/**
* Obtains an instance of {@code Year} from a text string using a specific formatter.
* <p>
* The text is parsed using the formatter, returning a year.
*
* @param {String} text the text to parse, not null
* @param {DateTimeFormatter} formatter the formatter to use, not null
* @return {Year} the parsed year, not null
* @throws DateTimeParseException if the text cannot be parsed
*/
static parseTextFormatter(text, formatter) {
requireNonNull(text, 'text');
requireNonNull(formatter, 'formatter');
requireInstance(formatter, DateTimeFormatter, 'formatter');
return formatter.parse(text, Year.FROM);
}
//-------------------------------------------------------------------------
/**
* Checks if the year is a leap year, according to the ISO proleptic
* calendar system rules.
* <p>
* This method applies the current rules for leap years across the whole time-line.
* In general, a year is a leap year if it is divisible by four without
* remainder. However, years divisible by 100, are not leap years, with
* the exception of years divisible by 400 which are.
* <p>
* For example, 1904 is a leap year it is divisible by 4.
* 1900 was not a leap year as it is divisible by 100, however 2000 was a
* leap year as it is divisible by 400.
* <p>
* The calculation is proleptic - applying the same rules into the far future and far past.
* This is historically inaccurate, but is correct for the ISO-8601 standard.
*
* @param {number} year the year to check
* @return {boolean} true if the year is leap, false otherwise
*/
static isLeap(year) {
return ((MathUtil.intMod(year, 4) === 0) && ((MathUtil.intMod(year, 100) !== 0) || (MathUtil.intMod(year, 400) === 0)));
}
/**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
* This year is used to enhance the accuracy of the returned range.
* If it is not possible to return the range, because the field is not supported
* or for some other reason, an exception is thrown.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The {@link #isSupported(TemporalField) supported fields} will return
* appropriate range instances.
* All other {@code ChronoField} instances will throw a {@code DateTimeException}.
* <p>
* If the field is not a {@code ChronoField}, then the result of this method
* is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}
* passing {@code this} as the argument.
* Whether the range can be obtained is determined by the field.
*
* @param {TemporalField} field the field to query the range for, not null
* @return {ValueRange} the range of valid values for the field, not null
* @throws DateTimeException if the range for the field cannot be obtained
*/
range(field) {
if (field === ChronoField.YEAR_OF_ERA) {
return (this._year <= 0 ? ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE));
}
return super.range(field);
}
/**
* Gets the value of the specified field from this year as an {@code int}.
* <p>
* This queries this year for the value for the specified field.
* The returned value will always be within the valid range of values for the field.
* If it is not possible to return the value, because the field is not supported
* or for some other reason, an exception is thrown.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The {@link #isSupported(TemporalField) supported fields} will return valid
* values based on this year.
* All other {@code ChronoField} instances will throw a {@code DateTimeException}.
* <p>
* If the field is not a {@code ChronoField}, then the result of this method
* is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
* passing {@code this} as the argument. Whether the value can be obtained,
* and what the value represents, is determined by the field.
*
* @param {TemporalField} field the field to get, not null
* @return {number} the value for the field
* @throws DateTimeException if a value for the field cannot be obtained
* @throws ArithmeticException if numeric overflow occurs
*/
get(field) {
return this.range(field).checkValidIntValue(this.getLong(field), field);
}
/**
* Gets the value of the specified field from this year as a {@code long}.
* <p>
* This queries this year for the value for the specified field.
* If it is not possible to return the value, because the field is not supported
* or for some other reason, an exception is thrown.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The {@link #isSupported(TemporalField) supported fields} will return valid
* values based on this year.
* All other {@code ChronoField} instances will throw a {@code DateTimeException}.
* <p>
* If the field is not a {@code ChronoField}, then the result of this method
* is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
* passing {@code this} as the argument. Whether the value can be obtained,
* and what the value represents, is determined by the field.
*
* @param {TemporalField} field the field to get, not null
* @return {number} the value for the field
* @throws DateTimeException if a value for the field cannot be obtained
* @throws ArithmeticException if numeric overflow occurs
*/
getLong(field) {
requireNonNull(field, 'field');
if (field instanceof ChronoField) {
switch (field) {
case ChronoField.YEAR_OF_ERA: return (this._year < 1 ? 1 - this._year : this._year);
case ChronoField.YEAR: return this._year;
case ChronoField.ERA: return (this._year < 1 ? 0 : 1);
}
throw new UnsupportedTemporalTypeException('Unsupported field: ' + field);
}
return field.getFrom(this);
}
//-----------------------------------------------------------------------
/**
* Checks if the year is a leap year, according to the ISO proleptic
* calendar system rules.
* <p>
* This method applies the current rules for leap years across the whole time-line.
* In general, a year is a leap year if it is divisible by four without
* remainder. However, years divisible by 100, are not leap years, with
* the exception of years divisible by 400 which are.
* <p>
* For example, 1904 is a leap year it is divisible by 4.
* 1900 was not a leap year as it is divisible by 100, however 2000 was a
* leap year as it is divisible by 400.
* <p>
* The calculation is proleptic - applying the same rules into the far future and far past.
* This is historically inaccurate, but is correct for the ISO-8601 standard.
*
* @return {boolean} true if the year is leap, false otherwise
*/
isLeap() {
return Year.isLeap(this._year);
}
//-----------------------------------------------------------------------
/**
* function overloading for {@link Year.plus}
*
* if called with 1 arguments, then {@link Year.plusAmount} is executed.
*
* Otherwise {@link Year.plusAmountToAddUnit} is executed.
*
* @param {!(TemporalAmount|number)} amount
* @param {TemporalUnit} unit
* @returns {Year}
*/
plus() {
if (arguments.length === 1) {
return this.plusAmount.apply(this, arguments);
} else {
return this.plusAmountToAddUnit.apply(this, arguments);
}
}
/**
* Returns a copy of this year with the specified period added.
* <p>
* This method returns a new year based on this year with the specified period added.
* The adder is typically {@link Period} but may be any other type implementing
* the {@link TemporalAmount} interface.
* The calculation is delegated to the specified adjuster, which typically calls
* back to {@link #plus(long, TemporalUnit)}.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param {TemporalAmount} amount the amount to add, not null
* @return {Year} based on this year with the addition made, not null
* @throws DateTimeException if the addition cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
plusAmount(amount) {
requireNonNull(amount, 'amount');
requireInstance(amount, TemporalAmount, 'amount');
return amount.addTo(this);
}
/**
* @param {number} amountToAdd
* @param {TemporalUnit} unit
* @return {Year} based on this year with the addition made, not null
* @throws DateTimeException if the addition cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
plusAmountToAddUnit(amountToAdd, unit) {
requireNonNull(amountToAdd, 'amountToAdd');
requireNonNull(unit, 'unit');
requireInstance(unit, TemporalUnit, 'unit');
if (unit instanceof ChronoUnit) {
switch (unit) {
case ChronoUnit.YEARS: return this.plusYears(amountToAdd);
case ChronoUnit.DECADES: return this.plusYears(MathUtil.safeMultiply(amountToAdd, 10));
case ChronoUnit.CENTURIES: return this.plusYears(MathUtil.safeMultiply(amountToAdd, 100));
case ChronoUnit.MILLENNIA: return this.plusYears(MathUtil.safeMultiply(amountToAdd, 1000));
case ChronoUnit.ERAS: return this.with(ChronoField.ERA, MathUtil.safeAdd(this.getLong(ChronoField.ERA), amountToAdd));
}
throw new UnsupportedTemporalTypeException('Unsupported unit: ' + unit);
}
return unit.addTo(this, amountToAdd);
}
/**
* Returns a copy of this year with the specified number of years added.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param {number} yearsToAdd the years to add, may be negative
* @return {Year} based on this year with the period added, not null
* @throws DateTimeException if the result exceeds the supported year range
*/
plusYears(yearsToAdd) {
if (yearsToAdd === 0) {
return this;
}
return Year.of(ChronoField.YEAR.checkValidIntValue(MathUtil.safeAdd(this._year, yearsToAdd)));
}
//-----------------------------------------------------------------------
/**
* function overloading for {@link Year.minus}
*
* if called with 1 argument, then {@link Year.minusAmount} is executed.
*
* Otherwise {@link Year.minusAmountToSubtractUnit} is executed.
*
* @param {!(TemporalAmount|number)} amount
* @param {TemporalUnit} unit
* @returns {Year}
*/
minus() {
if (arguments.length === 1) {
return this.minusAmount.apply(this, arguments);
} else {
return this.minusAmountToSubtractUnit.apply(this, arguments);
}
}
/**
* Returns a copy of this year with the specified period subtracted.
* <p>
* This method returns a new year based on this year with the specified period subtracted.
* The subtractor is typically {@link Period} but may be any other type implementing
* the {@link TemporalAmount} interface.
* The calculation is delegated to the specified adjuster, which typically calls
* back to {@link #minus(long, TemporalUnit)}.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param {TemporalAmount} amount the amount to subtract, not null
* @return {Year} based on this year with the subtraction made, not null
* @throws DateTimeException if the subtraction cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
minusAmount(amount) {
return amount.subtractFrom(this);
}
/**
* @param {number} amountToSubtract the amount to subtract, not null
* @param {TemporalUnit} unit
* @return {Year} based on this year with the subtraction made, not null
* @throws DateTimeException {@inheritDoc}
* @throws ArithmeticException {@inheritDoc}
*/
minusAmountToSubtractUnit(amountToSubtract, unit) {
return (amountToSubtract === MathUtil.MIN_SAFE_INTEGER ? this.plus(MathUtil.MAX_SAFE_INTEGER, unit).plus(1, unit) : this.plus(-amountToSubtract, unit));
}
/**
* Returns a copy of this year with the specified number of years subtracted.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param {number} yearsToSubtract the years to subtract, may be negative
* @return {Year} based on this year with the period subtracted, not null
* @throws DateTimeException if the result exceeds the supported year range
*/
minusYears(yearsToSubtract) {
return (yearsToSubtract === MathUtil.MIN_SAFE_INTEGER ? this.plusYears(MathUtil.MAX_SAFE_INTEGER).plusYears(1) : this.plusYears(-yearsToSubtract));
}
/**
* Adjusts the specified temporal object to have this year.
* <p>
* This returns a temporal object of the same observable type as the input
* with the year changed to be the same as this.
* <p>
* The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
* passing {@link ChronoField#YEAR} as the field.
* If the specified temporal object does not use the ISO calendar system then
* a {@code DateTimeException} is thrown.
* <p>
* In most cases, it is clearer to reverse the calling pattern by using
* {@link Temporal#with(TemporalAdjuster)}:
* <pre>
* // these two lines are equivalent, but the second approach is recommended
* temporal = thisYear.adjustInto(temporal);
* temporal = temporal.with(thisYear);
* </pre>
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param {Temporal} temporal the target object to be adjusted, not null
* @return {Temporal} the adjusted object, not null
* @throws DateTimeException if unable to make the adjustment
* @throws ArithmeticException if numeric overflow occurs
*/
adjustInto(temporal) {
requireNonNull(temporal, 'temporal');
/* TODO: only IsoChronology for now
if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
throw new DateTimeException("Adjustment only supported on ISO date-time");
}*/
return temporal.with(ChronoField.YEAR, this._year);
}
/**
* Checks if the month-day is valid for this year.
* <p>
* This method checks whether this year and the input month and day form
* a valid date.
*
* @param {MonthDay} monthDay the month-day to validate, null returns false
* @return {boolean} true if the month and day are valid for this year
*/
isValidMonthDay(monthDay) {
return monthDay != null && monthDay.isValidYear(this._year);
}
/**
* Gets the length of this year in days.
*
* @return {number} the length of this year in days, 365 or 366
*/
length() {
return this.isLeap() ? 366 : 365;
}
//-----------------------------------------------------------------------
/**
* Combines this year with a day-of-year to create a {@code LocalDate}.
* <p>
* This returns a {@code LocalDate} formed from this year and the specified day-of-year.
* <p>
* The day-of-year value 366 is only valid in a leap year.
*
* @param {number} dayOfYear the day-of-year to use, not null
* @return {LocalDate} the local date formed from this year and the specified date of year, not null
* @throws DateTimeException if the day of year is zero or less, 366 or greater or equal
* to 366 and this is not a leap year
*/
atDay(dayOfYear) {
return LocalDate.ofYearDay(this._year, dayOfYear);
}
/**
* function overloading for {@link Year.atMonth}
*
* if called with 1 arguments and first argument is instance of Month, then {@link Year.atMonthMonth} is executed.
*
* Otherwise {@link Year.atMonthNumber} is executed.
*
* @param {TemporalUnit} unit
* @returns {YearMonth}
*/
atMonth() {
if (arguments.length === 1 && arguments[0] instanceof Month) {
return this.atMonthMonth.apply(this, arguments);
} else {
return this.atMonthNumber.apply(this, arguments);
}
}
/**
* Combines this year with a month to create a {@code YearMonth}.
* <p>
* This returns a {@code YearMonth} formed from this year and the specified month.
* All possible combinations of year and month are valid.
* <p>
* This method can be used as part of a chain to produce a date:
* <pre>
* LocalDate date = year.atMonth(month).atDay(day);
* </pre>
*
* @param {Month} month the month-of-year to use, not null
* @return {YearMonth} the year-month formed from this year and the specified month, not null
*/
atMonthMonth(month) {
requireNonNull(month, 'month');
requireInstance(month, Month, 'month');
return YearMonth.of(this._year, month);
}
/**
* Combines this year with a month to create a {@code YearMonth}.
* <p>
* This returns a {@code YearMonth} formed from this year and the specified month.
* All possible combinations of year and month are valid.
* <p>
* This method can be used as part of a chain to produce a date:
* <pre>
* LocalDate date = year.atMonth(month).atDay(day);
* </pre>
*
* @param {number} month the month-of-year to use, from 1 (January) to 12 (December)
* @return {YearMonth} the year-month formed from this year and the specified month, not null
* @throws DateTimeException if the month is invalid
*/
atMonthNumber(month) {
requireNonNull(month, 'month');
return YearMonth.of(this._year, month);
}
/**
* Combines this year with a month-day to create a {@code LocalDate}.
* <p>
* This returns a {@code LocalDate} formed from this year and the specified month-day.
* <p>
* A month-day of February 29th will be adjusted to February 28th in the resulting
* date if the year is not a leap year.
*
* @param {MonthDay} monthDay the month-day to use, not null
* @return {LocalDate} the local date formed from this year and the specified month-day, not null
*/
atMonthDay(monthDay) {
requireNonNull(monthDay, 'monthDay');
requireInstance(monthDay, MonthDay, 'monthDay');
return monthDay.atYear(this._year);
}
//-----------------------------------------------------------------------
/**
* Queries this year using the specified query.
* <p>
* This queries this year using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
*
* @param {TemporalQuery} query the query to invoke, not null
* @return {*} the query result, null may be returned (defined by the query)
* @throws DateTimeException if unable to query (defined by the query)
* @throws ArithmeticException if numeric overflow occurs (defined by the query)
*/
query(query) {
requireNonNull(query, 'query()');
requireInstance(query, TemporalQuery, 'query()');
if (query === TemporalQueries.chronology()) {
return IsoChronology.INSTANCE;
} else if (query === TemporalQueries.precision()) {
return ChronoUnit.YEARS;
} else if (query === TemporalQueries.localDate() || query === TemporalQueries.localTime() ||
query === TemporalQueries.zone() || query === TemporalQueries.zoneId() || query === TemporalQueries.offset()) {
return null;
}
return super.query(query);
}
//-----------------------------------------------------------------------
/**
* Compares this year to another year.
* <p>
* The comparison is based on the value of the year.
* It is "consistent with equals", as defined by {@link Comparable}.
*
* @param {Year} other the other year to compare to, not null
* @return {number} the comparator value, negative if less, positive if greater
*/
compareTo(other) {
requireNonNull(other, 'other');
requireInstance(other, Year, 'other');
return this._year - other._year;
}
/**
* Is this year after the specified year.
*
* @param {Year} other the other year to compare to, not null
* @return {boolean} true if this is after the specified year
*/
isAfter(other) {
requireNonNull(other, 'other');
requireInstance(other, Year, 'other');
return this._year > other._year;
}
/**
* Is this year before the specified year.
*
* @param {Year} other the other year to compare to, not null
* @return {boolean} true if this point is before the specified year
*/
isBefore(other) {
requireNonNull(other, 'other');
requireInstance(other, Year, 'other');
return this._year < other._year;
}
/**
* Outputs this year as a {@code String} using the formatter.
* <p>
* This year will be passed to the formatter
* {@link DateTimeFormatter#format(TemporalAccessor) print method}.
*
* @param {DateTimeFormatter} formatter the formatter to use, not null
* @return {String} the formatted year string, not null
* @throws DateTimeException if an error occurs during printing
*/
format(formatter) {
requireNonNull(formatter, 'formatter');
requireInstance(formatter, DateTimeFormatter, 'formatter');
return formatter.format(this);
}
/**
* Checks if this year is equal to the specified {@link Year}.
* <p>
* The comparison is based on the value
*
* @param {*} otherYear - the other year, null returns false
* @return {boolean} true if the other duration is equal to this one
*/
equals(otherYear) {
if (this === otherYear) {
return true;
}
if (otherYear instanceof Year) {
return this.value() === otherYear.value();
}
return false;
}
/**
* Outputs this year as a {@code String}.
*
* @return {String} a string representation of this year, not null
*/
toString() {
return '' + this._year;
}
}
var PARSER;
export function _init() {
Year.MIN_VALUE = YearConstants.MIN_VALUE;
Year.MAX_VALUE = YearConstants.MAX_VALUE;
PARSER = new DateTimeFormatterBuilder()
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
.toFormatter();
Year.FROM = createTemporalQuery('Year.FROM', (temporal) => {
return Year.from(temporal);
});
}

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

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc