Skip to content

Commit

Permalink
Create luxon.d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
GillesDebunne committed Sep 8, 2019
1 parent 9cb7ed1 commit 63940bd
Show file tree
Hide file tree
Showing 17 changed files with 616 additions and 86 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
node_modules
.tern-port
build
node_modules/
build/
transpiled/
#*
.#*
coverage/
.tern-port
.DS_Store
.external-ecmascript.js
.idea
.vscode
.vscode
20 changes: 13 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
"@babel/plugin-external-helpers": "latest",
"@babel/plugin-proposal-optional-chaining": "latest",
"@babel/preset-env": "latest",
"@types/jest": "^24.0.18",
"@typescript-eslint/eslint-plugin": "^2.1.0",
"@typescript-eslint/parser": "^2.1.0",
"@types/jest": "latest",
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "latest",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "11.0.0-beta.0",
"babel-jest": "latest",
Expand All @@ -63,22 +63,22 @@
"eslint-plugin-promise": "latest",
"eslint-plugin-react": "latest",
"eslint-plugin-standard": "latest",
"fs-extra": "^6.0.1",
"fs-extra": "latest",
"full-icu": "latest",
"husky": "latest",
"jest": "latest",
"lint-staged": "latest",
"prettier": "1.18.2",
"rimraf": "^3.0.0",
"rimraf": "latest",
"rollup": "latest",
"rollup-plugin-babel": "latest",
"rollup-plugin-babel-minify": "latest",
"rollup-plugin-commonjs": "latest",
"rollup-plugin-node-resolve": "latest",
"rollup-plugin-typescript": "latest",
"ts-jest": "^24.0.2",
"ts-jest": "latest",
"tslib": "latest",
"typescript": "^3.5.3",
"typescript": "latest",
"uglify-js": "latest"
},
"main": "build/node/luxon.js",
Expand Down
34 changes: 18 additions & 16 deletions src/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import {
DateTimeWithZoneOptions
} from "./types/datetime";
import { DurationUnit } from "./types/duration";
import { LocaleOptions } from "./types/locale";
import { LocaleOptions, NumberingSystem, CalendarSystem } from "./types/locale";
import { ThrowOnInvalid } from "./types/common";

const MAX_DATE = 8.64e15;
Expand Down Expand Up @@ -1142,11 +1142,13 @@ export default class DateTime {
* @return {Object}
*/
resolvedLocaleOpts(options: LocaleOptions & DateTimeFormatOptions = {}) {
const { locale, numberingSystem, calendar } = Formatter.create(
const { locale, numberingSystem: ns, calendar } = Formatter.create(
this.loc.clone(options),
options
).resolvedOptions(this);
return { locale, numberingSystem, outputCalendar: calendar };
const numberingSystem = ns as NumberingSystem;
const outputCalendar = calendar as CalendarSystem;
return { locale, numberingSystem, outputCalendar };
}

// TRANSFORM
Expand Down Expand Up @@ -1214,7 +1216,7 @@ export default class DateTime {

/**
* "Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime.
* @param {Object} options - the options to set
* @param {Object} [options] - the options to set
* @param {string} [options.locale] - ;
* @param {CalendarSystem} [options.outputCalendar] - ;
* @param {NumberingSystem} [options.numberingSystem] - ;
Expand Down Expand Up @@ -1618,7 +1620,7 @@ export default class DateTime {

/**
* Return the difference between two DateTimes as a Duration.
* @param {DateTime} otherDateTime - the DateTime to compare this one to
* @param {DateTime} other - the DateTime to compare this one to
* @param {string|string[]} [unit=['milliseconds']] - the unit or array of units (such as 'hours' or 'days') to include in the duration.
* @param {Object} options - options that affect the creation of the Duration
* @param {string} [options.conversionAccuracy='casual'] - the conversion system to use
Expand All @@ -1632,7 +1634,7 @@ export default class DateTime {
* @return {Duration}
*/
diff(
otherDateTime: DateTime,
other: DateTime,
unit: DurationUnit | DurationUnit[] = "milliseconds",
options: DiffOptions = {}
) {
Expand All @@ -1646,9 +1648,9 @@ export default class DateTime {
// GILLES added this test, for an invariant used in diff()
if (units.length === 0) throw new InvalidArgumentError("At least one unit must be specified");

const otherIsLater = otherDateTime.valueOf() > this.valueOf(),
earlier = otherIsLater ? this : otherDateTime,
later = otherIsLater ? otherDateTime : this,
const otherIsLater = other.valueOf() > this.valueOf(),
earlier = otherIsLater ? this : other,
later = otherIsLater ? other : this,
diffed = diff(earlier, later, units, durOpts);

return otherIsLater ? diffed.negate() : diffed;
Expand All @@ -1669,26 +1671,26 @@ export default class DateTime {

/**
* Return an Interval spanning between this DateTime and another DateTime
* @param {DateTime} otherDateTime - the other end point of the Interval
* @param {DateTime} other - the other end point of the Interval
* @return {Interval}
*/
until(otherDateTime: DateTime) {
return Interval.fromDateTimes(this, otherDateTime);
until(other: DateTime) {
return Interval.fromDateTimes(this, other);
}

/**
* Return whether this DateTime is in the same unit of time as another DateTime
* @param {DateTime} otherDateTime - the other DateTime
* @param {DateTime} other - the other DateTime
* @param {string} unit - the unit of time to check sameness on
* @example DateTime.local().hasSame(otherDT, 'day'); //~> true if both have the same calendar day
* @return {boolean}
*/
hasSame(otherDateTime: DateTime, unit: DurationUnit) {
hasSame(other: DateTime, unit: DurationUnit) {
if (Duration.normalizeUnit(unit) === "milliseconds") {
// GILLES added normalizeUnit
return this.valueOf() === otherDateTime.valueOf();
return this.valueOf() === other.valueOf();
} else {
const inputMs = otherDateTime.valueOf();
const inputMs = other.valueOf();
return this.startOf(unit).valueOf() <= inputMs && inputMs <= this.endOf(unit).valueOf();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default class Duration {
/**
* @private
*/
constructor(config: Config) {
private constructor(config: Config) {
const accurate = config.conversionAccuracy === "longterm" || false;
/**
* @access private
Expand Down
7 changes: 6 additions & 1 deletion src/impl/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,12 @@ export function untruncateYear(year: number) {

// PARSING

export function parseZoneInfo(ts: number, offsetFormat: string, locale: string, timeZone?: string) {
export function parseZoneInfo(
ts: number,
offsetFormat?: string,
locale?: string,
timeZone?: string
) {
const date = new Date(ts),
intlOpts = {
hour12: false,
Expand Down
6 changes: 3 additions & 3 deletions src/interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface Config {
* * **Interrogation** To analyze the Interval, use {@link count}, {@link length}, {@link hasSame}, {@link contains}, {@link isAfter}, or {@link isBefore}.
* * **Transformation** To create other Intervals out of this one, use {@link set}, {@link splitAt}, {@link splitBy}, {@link divideEqually}, {@link merge}, {@link xor}, {@link union}, {@link intersection}, or {@link difference}.
* * **Comparison** To compare this Interval to another one, use {@link equals}, {@link overlaps}, {@link abutsStart}, {@link abutsEnd}, {@link engulfs}
* * **Output*** To convert the Interval into other representations, see {@link toString}, {@link toISO}, {@link toFormat}, and {@link toDuration}.
* * **Output** To convert the Interval into other representations, see {@link toString}, {@link toISO}, {@link toFormat}, and {@link toDuration}.
*/
export default class Interval {
// Private readonly fields
Expand All @@ -44,7 +44,7 @@ export default class Interval {
/**
* @private
*/
constructor(config: Config) {
private constructor(config: Config) {
validateStartEnd(config.start, config.end);

/**
Expand Down Expand Up @@ -242,7 +242,7 @@ export default class Interval {
* @param {DateTime} values.end - the ending DateTime
* @return {Interval}
*/
set({ start, end }: IntervalObject = {}) {
set({ start, end }: IntervalObject) {
return Interval.fromDateTimes(start || this.s, end || this.e);
}

Expand Down
Loading

0 comments on commit 63940bd

Please sign in to comment.