Skip to content

Commit

Permalink
v4.0.2 (#254)
Browse files Browse the repository at this point in the history
* Updated CHANGELOG

* Fixed type declarations

* Changelog typo

* Updated circleci config to v2

* Updated yarn lock

* Typo and version bump

* Added .DS_Store

* Added circleci workflow

* Rename circle config

* Circle config typo

* Use circle with browsers

* Using circle image

* Bump requirement
  • Loading branch information
TristanJM authored Feb 22, 2019
1 parent ad43eca commit 46807b3
Show file tree
Hide file tree
Showing 12 changed files with 3,124 additions and 1,710 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
test:
docker:
- image: node:8.11
- image: circleci/node:8.11-browsers
working_directory: ~

steps:
Expand Down Expand Up @@ -30,4 +30,4 @@ workflows:
version: 2
tests:
jobs:
- test:
- test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.idea
dist/
docs/
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [4.0.2]
### Added
* Added TypeScript & flow types missing options argument for `add` method
* Added overloaded TypeScript declarations allowing for calling `moment.range()` without arguments

### Changed
* Changed second parameter of `diff` & `duration` from `rounded` to `precise` to reflect the underlying moment method
* Changed the `moment.range()` & `DateRange` `constructor` types to allow mixed `Date` & `Moment` parameters
* Changed the `interval`/`unit` flow parameter types in the `by`, `diff`, `duration`, `reverseBy` & `snapTo` to include all strings allowed by moment
* Changed internal TypeScript version to `3.3.3333`
* Changed CircleCI to version `2`

### Fixed
* Fixed the return type of `add` and `intersect` to `DateRange | null` as opposed to `DateRange | undefined`
* Fixed the flow `toDate()` method return type from an array of `Date`s to a `Date` tuple

## [4.0.1]
### Fixed

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ range.diff('days'); // 92
range.diff(); // 7945200000
```

Optionally you may specify if the difference should be rounded, by default it
mimics moment-js' behaviour and rounds the values:
Optionally you may specify if the difference should not be truncated. By default it
mimics moment-js' behaviour and truncates the values:

``` js
const d1 = new Date(Date.UTC(2011, 4, 1));
Expand All @@ -661,7 +661,7 @@ const range = moment.range(d1, d2);

range.diff('days') // 4
range.diff('days', false) // 4
range.diff('days', true) // 4.5
range.diff('days', true) // 4.75
```

`#duration` is an alias for `#diff` and they may be used interchangeably.
Expand Down
22 changes: 10 additions & 12 deletions lib/moment-range.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ export class DateRange {
start: Moment;
end: Moment;

constructor(start: Date, end: Date);
constructor(start: Moment, end: Moment);
constructor(range: [Date, Date]);
constructor(range: [Moment, Moment]);
constructor(start: Date | Moment, end: Date | Moment);
constructor(range: [Date | Moment, Date | Moment]);
constructor(range: string);
constructor();

adjacent(other: DateRange): boolean;

add(other: DateRange, options?: { adjacent?: boolean; }): DateRange | undefined;
add(other: DateRange, options?: { adjacent?: boolean }): DateRange | null;

by(interval: unitOfTime.Diff, options?: { excludeEnd?: boolean; step?: number; }): Iterable<Moment>;
// @deprecated 4.0.0
Expand All @@ -31,11 +30,11 @@ export class DateRange {
// @deprecated 4.0.0
contains(other: Date | DateRange | Moment, options?: { exclusive?: boolean; }): boolean;

diff(unit?: unitOfTime.Diff, rounded?: boolean): number;
diff(unit?: unitOfTime.Diff, precise?: boolean): number;

duration(unit?: unitOfTime.Diff, rounded?: boolean): number;
duration(unit?: unitOfTime.Diff, precise?: boolean): number;

intersect(other: DateRange): DateRange | undefined;
intersect(other: DateRange): DateRange | null;

isEqual(other: DateRange): boolean;

Expand Down Expand Up @@ -63,11 +62,10 @@ export class DateRange {
}

export interface MomentRangeStaticMethods {
range(start: Date, end: Date): DateRange;
range(start: Moment, end: Moment): DateRange;
range(range: [Date, Date]): DateRange;
range(range: [Moment, Moment]): DateRange;
range(start: Date | Moment, end: Date | Moment): DateRange;
range(range: [Date | Moment, Date | Moment]): DateRange;
range(range: string): DateRange;
range(): DateRange;

rangeFromInterval(interval: unitOfTime.Diff, count?: number, date?: Date | Moment): DateRange;
rangeFromISOString(isoTimeInterval: string): DateRange;
Expand Down
14 changes: 7 additions & 7 deletions lib/moment-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ export class DateRange {
return (startInRange && endInRange);
}

diff(unit, rounded) {
return this.end.diff(this.start, unit, rounded);
diff(unit, precise) {
return this.end.diff(this.start, unit, precise);
}

duration(unit, rounded) {
return this.diff(unit, rounded);
duration(unit, precise) {
return this.diff(unit, precise);
}

intersect(other) {
Expand Down Expand Up @@ -222,13 +222,13 @@ export class DateRange {
}

overlaps(other, options = { adjacent: false }) {
const intersect = (this.intersect(other) !== null);
const intersects = (this.intersect(other) !== null);

if (options.adjacent && !intersect) {
if (options.adjacent && !intersects) {
return this.adjacent(other);
}

return intersect;
return intersects;
}

reverseBy(interval, options = { excludeStart: false, step: 1 }) {
Expand Down
44 changes: 28 additions & 16 deletions lib/moment-range.js.flow
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import type Moment from "moment";
import type Moment from 'moment';

declare module "moment-range" {
declare type Shorthand = 'years' | 'year' | 'quarters' | 'quarter' | 'months' | 'month' | 'weeks' | 'week' | 'days' | 'day' | 'hours' | 'hour' | 'minutes' | 'minute' | 'seconds' | 'second' | 'milliseconds' | 'millisecond';
declare module 'moment-range' {
declare type Base = (
'year' | 'years' | 'y' |
'month' | 'months' | 'M' |
'week' | 'weeks' | 'w' |
'day' | 'days' | 'd' |
'hour' | 'hours' | 'h' |
'minute' | 'minutes' | 'm' |
'second' | 'seconds' | 's' |
'millisecond' | 'milliseconds' | 'ms'
);

declare type _quarter = 'quarter' | 'quarters' | 'Q';

declare type UnitOfTimeDiff = Base | _quarter;

declare function extendMoment(moment: Class<Moment>): Class<Moment>;

declare class DateRange {
start: Moment;
end: Moment;

constructor(start: Date, end: Date): void;
constructor(start: Moment, end: Moment): void;
constructor(range: [Date, Date]): void;
constructor(range: [Moment, Moment]): void;
constructor(start: Date | Moment, end: Date | Moment): void;
constructor(range: [Date | Moment, Date | Moment]): void;
constructor(range: string): void;
constructor(): void;

adjacent(other: DateRange): bool;

add(other: DateRange): ?DateRange;
add(other: DateRange, options?: {| adjacent?: bool |}): ?DateRange;

by(interval: Shorthand, options?: {| excludeEnd?: bool, step?: number, |}): Iterable<Moment>;
by(interval: UnitOfTimeDiff, options?: {| excludeEnd?: bool, step?: number, |}): Iterable<Moment>;
// @deprecated 4.0.0
by(interval: Shorthand, options?: {| exclusive?: bool, step?: number, |}): Iterable<Moment>;
by(interval: UnitOfTimeDiff, options?: {| exclusive?: bool, step?: number, |}): Iterable<Moment>;

byRange(interval: DateRange, options?: {| excludeEnd?: bool; step?: number, |}): Iterable<Moment>;
// @deprecated 4.0.0
Expand All @@ -35,9 +47,9 @@ declare module "moment-range" {
// @deprecated 4.0.0
contains(other: Date | DateRange | Moment, options?: {| exclusive: bool, |}): bool;

diff(unit: ?Shorthand, rounded: ?bool): number;
diff(unit: ?UnitOfTimeDiff, precise: ?bool): number;

duration(unit: ?Shorthand, rounded: ?bool): number;
duration(unit: ?UnitOfTimeDiff, precise: ?bool): number;

intersect(other: DateRange): ?DateRange;

Expand All @@ -47,19 +59,19 @@ declare module "moment-range" {

overlaps(other: DateRange, options?: {| adjacent: bool, |}): bool;

reverseBy(interval: Shorthand, options?: {| excludeStart?: bool, step?: number, |}): Iterable<Moment>;
reverseBy(interval: UnitOfTimeDiff, options?: {| excludeStart?: bool, step?: number, |}): Iterable<Moment>;
// @deprecated 4.0.0
reverseBy(interval: Shorthand, options?: {| exclusive?: bool, step?: number, |}): Iterable<Moment>;
reverseBy(interval: UnitOfTimeDiff, options?: {| exclusive?: bool, step?: number, |}): Iterable<Moment>;

reverseByRange(interval: DateRange, options?: {| excludeStart?: bool, step?: number, |}): Iterable<Moment>;
// @deprecated 4.0.0
reverseByRange(interval: DateRange, options?: {| exclusive?: bool, step?: number, |}): Iterable<Moment>;

snapTo(interval: Shorthand): DateRange;
snapTo(interval: UnitOfTimeDiff): DateRange;

subtract(other: DateRange): Array<DateRange>;

toDate(): Array<Date>;
toDate(): [Date, Date];

toString(): string;

Expand Down
2 changes: 1 addition & 1 deletion lib/tests/moment-range.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ describe('DateRange', function() {
expect(dr.diff()).to.equal(7948800000);
});

it('should optionally pass the rounded argument', function() {
it('should optionally pass the precise argument', function() {
const d1 = new Date(Date.UTC(2011, 4, 1));
const d2 = new Date(Date.UTC(2011, 4, 5, 12));
const dr = moment.range(d1, d2);
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"homepage": "https://github.com/rotaready/moment-range",
"bugs": "https://github.com/rotaready/moment-range/issues",
"main": "./dist/moment-range",
"version": "4.0.1",
"version": "4.0.2",
"engines": {
"node": "*"
},
Expand All @@ -36,15 +36,15 @@
],
"scripts": {
"build": "webpack -p",
"check": "yarn run check:flow && yarn run check:typescript",
"check": "yarn check:flow && yarn check:typescript",
"check:flow": "flow",
"check:typescript": "tsc --project ./typing-tests/typescript",
"doctoc": "doctoc README.md --github",
"lint": "eslint ./lib/",
"prepublishOnly": "yarn run build && cp ./lib/*.flow ./lib/*.d.ts ./dist",
"preversion": "yarn run check && yarn run lint && yarn run test",
"prepublishOnly": "yarn build && cp ./lib/*.flow ./lib/*.d.ts ./dist",
"preversion": "yarn check && yarn lint && yarn test",
"test": "karma start ./karma.conf.js",
"version": "yarn run build && cp ./lib/*.flow ./lib/*.d.ts ./dist"
"version": "yarn build && cp ./lib/*.flow ./lib/*.d.ts ./dist"
},
"typings": "./dist/moment-range.d.ts",
"devDependencies": {
Expand All @@ -55,7 +55,7 @@
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-stage-0": "^6.16.0",
"doctoc": "^1.2.0",
"doctoc": "^1.4.0",
"eslint": "^3.11.1",
"eslint-loader": "^1.6.1",
"expect.js": "^0.3.1",
Expand All @@ -70,7 +70,7 @@
"karma-webpack": "^2.0.2",
"mocha": "^2.5.3",
"moment": "^2.17.1",
"typescript": "^2.6.2",
"typescript": "^3.3.3333",
"webpack": "^2.2.1"
},
"peerDependencies": {
Expand Down
10 changes: 10 additions & 0 deletions typing-tests/flow/moment-range.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ const moment = extendMoment(M);

moment.range(new Date(), new Date());
moment.range(moment(), moment());
moment.range(moment(), new Date());
moment.range(new Date(), moment());
moment.range([new Date(), new Date()]);
moment.range([moment(), moment()]);
moment.range([moment(), new Date()]);
moment.range([new Date(), moment()]);
moment.range('year');
moment.range();

moment.rangeFromInterval('day');
moment.rangeFromInterval('day', 3);
Expand All @@ -28,9 +33,14 @@ moment().within(moment.range('hour'));

new DateRange(new Date(), new Date());
new DateRange(moment(), moment());
new DateRange(moment(), new Date());
new DateRange(new Date(), moment());
new DateRange([new Date(), new Date()]);
new DateRange([moment(), moment()]);
new DateRange([moment(), new Date()]);
new DateRange([new Date(), moment()]);
new DateRange('year');
new DateRange();

// Adjacent
const range001 = new DateRange('year');
Expand Down
10 changes: 10 additions & 0 deletions typing-tests/typescript/moment-range.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ const moment = extendMoment(M);

moment.range(new Date(), new Date());
moment.range(moment(), moment());
moment.range(moment(), new Date());
moment.range(new Date(), moment());
moment.range([new Date(), new Date()]);
moment.range([moment(), moment()]);
moment.range([moment(), new Date()]);
moment.range([new Date(), moment()]);
moment.range('year');
moment.range();

moment.rangeFromInterval('day');
moment.rangeFromInterval('day', 3);
Expand All @@ -27,9 +32,14 @@ moment().within(moment.range('hour'));

new DateRange(new Date(), new Date());
new DateRange(moment(), moment());
new DateRange(moment(), new Date());
new DateRange(new Date(), moment());
new DateRange([new Date(), new Date()]);
new DateRange([moment(), moment()]);
new DateRange([moment(), new Date()]);
new DateRange([new Date(), moment()]);
new DateRange('year');
new DateRange();

// Adjacent
const range001 = new DateRange('year');
Expand Down
Loading

0 comments on commit 46807b3

Please sign in to comment.