Skip to content

Commit 46807b3

Browse files
authored
v4.0.2 (#254)
* 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
1 parent ad43eca commit 46807b3

File tree

12 files changed

+3124
-1710
lines changed

12 files changed

+3124
-1710
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
test:
44
docker:
5-
- image: node:8.11
5+
- image: circleci/node:8.11-browsers
66
working_directory: ~
77

88
steps:
@@ -30,4 +30,4 @@ workflows:
3030
version: 2
3131
tests:
3232
jobs:
33-
- test:
33+
- test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_Store
12
.idea
23
dist/
34
docs/

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [4.0.2]
11+
### Added
12+
* Added TypeScript & flow types missing options argument for `add` method
13+
* Added overloaded TypeScript declarations allowing for calling `moment.range()` without arguments
14+
15+
### Changed
16+
* Changed second parameter of `diff` & `duration` from `rounded` to `precise` to reflect the underlying moment method
17+
* Changed the `moment.range()` & `DateRange` `constructor` types to allow mixed `Date` & `Moment` parameters
18+
* Changed the `interval`/`unit` flow parameter types in the `by`, `diff`, `duration`, `reverseBy` & `snapTo` to include all strings allowed by moment
19+
* Changed internal TypeScript version to `3.3.3333`
20+
* Changed CircleCI to version `2`
21+
22+
### Fixed
23+
* Fixed the return type of `add` and `intersect` to `DateRange | null` as opposed to `DateRange | undefined`
24+
* Fixed the flow `toDate()` method return type from an array of `Date`s to a `Date` tuple
25+
1026
## [4.0.1]
1127
### Fixed
1228

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ range.diff('days'); // 92
651651
range.diff(); // 7945200000
652652
```
653653

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

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

662662
range.diff('days') // 4
663663
range.diff('days', false) // 4
664-
range.diff('days', true) // 4.5
664+
range.diff('days', true) // 4.75
665665
```
666666

667667
`#duration` is an alias for `#diff` and they may be used interchangeably.

lib/moment-range.d.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ export class DateRange {
55
start: Moment;
66
end: Moment;
77

8-
constructor(start: Date, end: Date);
9-
constructor(start: Moment, end: Moment);
10-
constructor(range: [Date, Date]);
11-
constructor(range: [Moment, Moment]);
8+
constructor(start: Date | Moment, end: Date | Moment);
9+
constructor(range: [Date | Moment, Date | Moment]);
1210
constructor(range: string);
11+
constructor();
1312

1413
adjacent(other: DateRange): boolean;
1514

16-
add(other: DateRange, options?: { adjacent?: boolean; }): DateRange | undefined;
15+
add(other: DateRange, options?: { adjacent?: boolean }): DateRange | null;
1716

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

34-
diff(unit?: unitOfTime.Diff, rounded?: boolean): number;
33+
diff(unit?: unitOfTime.Diff, precise?: boolean): number;
3534

36-
duration(unit?: unitOfTime.Diff, rounded?: boolean): number;
35+
duration(unit?: unitOfTime.Diff, precise?: boolean): number;
3736

38-
intersect(other: DateRange): DateRange | undefined;
37+
intersect(other: DateRange): DateRange | null;
3938

4039
isEqual(other: DateRange): boolean;
4140

@@ -63,11 +62,10 @@ export class DateRange {
6362
}
6463

6564
export interface MomentRangeStaticMethods {
66-
range(start: Date, end: Date): DateRange;
67-
range(start: Moment, end: Moment): DateRange;
68-
range(range: [Date, Date]): DateRange;
69-
range(range: [Moment, Moment]): DateRange;
65+
range(start: Date | Moment, end: Date | Moment): DateRange;
66+
range(range: [Date | Moment, Date | Moment]): DateRange;
7067
range(range: string): DateRange;
68+
range(): DateRange;
7169

7270
rangeFromInterval(interval: unitOfTime.Diff, count?: number, date?: Date | Moment): DateRange;
7371
rangeFromISOString(isoTimeInterval: string): DateRange;

lib/moment-range.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ export class DateRange {
158158
return (startInRange && endInRange);
159159
}
160160

161-
diff(unit, rounded) {
162-
return this.end.diff(this.start, unit, rounded);
161+
diff(unit, precise) {
162+
return this.end.diff(this.start, unit, precise);
163163
}
164164

165-
duration(unit, rounded) {
166-
return this.diff(unit, rounded);
165+
duration(unit, precise) {
166+
return this.diff(unit, precise);
167167
}
168168

169169
intersect(other) {
@@ -222,13 +222,13 @@ export class DateRange {
222222
}
223223

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

227-
if (options.adjacent && !intersect) {
227+
if (options.adjacent && !intersects) {
228228
return this.adjacent(other);
229229
}
230230

231-
return intersect;
231+
return intersects;
232232
}
233233

234234
reverseBy(interval, options = { excludeStart: false, step: 1 }) {

lib/moment-range.js.flow

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
1-
import type Moment from "moment";
1+
import type Moment from 'moment';
22

3-
declare module "moment-range" {
4-
declare type Shorthand = 'years' | 'year' | 'quarters' | 'quarter' | 'months' | 'month' | 'weeks' | 'week' | 'days' | 'day' | 'hours' | 'hour' | 'minutes' | 'minute' | 'seconds' | 'second' | 'milliseconds' | 'millisecond';
3+
declare module 'moment-range' {
4+
declare type Base = (
5+
'year' | 'years' | 'y' |
6+
'month' | 'months' | 'M' |
7+
'week' | 'weeks' | 'w' |
8+
'day' | 'days' | 'd' |
9+
'hour' | 'hours' | 'h' |
10+
'minute' | 'minutes' | 'm' |
11+
'second' | 'seconds' | 's' |
12+
'millisecond' | 'milliseconds' | 'ms'
13+
);
14+
15+
declare type _quarter = 'quarter' | 'quarters' | 'Q';
16+
17+
declare type UnitOfTimeDiff = Base | _quarter;
518

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

821
declare class DateRange {
922
start: Moment;
1023
end: Moment;
1124

12-
constructor(start: Date, end: Date): void;
13-
constructor(start: Moment, end: Moment): void;
14-
constructor(range: [Date, Date]): void;
15-
constructor(range: [Moment, Moment]): void;
25+
constructor(start: Date | Moment, end: Date | Moment): void;
26+
constructor(range: [Date | Moment, Date | Moment]): void;
1627
constructor(range: string): void;
28+
constructor(): void;
1729

1830
adjacent(other: DateRange): bool;
1931

20-
add(other: DateRange): ?DateRange;
32+
add(other: DateRange, options?: {| adjacent?: bool |}): ?DateRange;
2133

22-
by(interval: Shorthand, options?: {| excludeEnd?: bool, step?: number, |}): Iterable<Moment>;
34+
by(interval: UnitOfTimeDiff, options?: {| excludeEnd?: bool, step?: number, |}): Iterable<Moment>;
2335
// @deprecated 4.0.0
24-
by(interval: Shorthand, options?: {| exclusive?: bool, step?: number, |}): Iterable<Moment>;
36+
by(interval: UnitOfTimeDiff, options?: {| exclusive?: bool, step?: number, |}): Iterable<Moment>;
2537

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

38-
diff(unit: ?Shorthand, rounded: ?bool): number;
50+
diff(unit: ?UnitOfTimeDiff, precise: ?bool): number;
3951

40-
duration(unit: ?Shorthand, rounded: ?bool): number;
52+
duration(unit: ?UnitOfTimeDiff, precise: ?bool): number;
4153

4254
intersect(other: DateRange): ?DateRange;
4355

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

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

50-
reverseBy(interval: Shorthand, options?: {| excludeStart?: bool, step?: number, |}): Iterable<Moment>;
62+
reverseBy(interval: UnitOfTimeDiff, options?: {| excludeStart?: bool, step?: number, |}): Iterable<Moment>;
5163
// @deprecated 4.0.0
52-
reverseBy(interval: Shorthand, options?: {| exclusive?: bool, step?: number, |}): Iterable<Moment>;
64+
reverseBy(interval: UnitOfTimeDiff, options?: {| exclusive?: bool, step?: number, |}): Iterable<Moment>;
5365

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

58-
snapTo(interval: Shorthand): DateRange;
70+
snapTo(interval: UnitOfTimeDiff): DateRange;
5971

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

62-
toDate(): Array<Date>;
74+
toDate(): [Date, Date];
6375

6476
toString(): string;
6577

lib/tests/moment-range.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ describe('DateRange', function() {
12811281
expect(dr.diff()).to.equal(7948800000);
12821282
});
12831283

1284-
it('should optionally pass the rounded argument', function() {
1284+
it('should optionally pass the precise argument', function() {
12851285
const d1 = new Date(Date.UTC(2011, 4, 1));
12861286
const d2 = new Date(Date.UTC(2011, 4, 5, 12));
12871287
const dr = moment.range(d1, d2);

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"homepage": "https://github.com/rotaready/moment-range",
2828
"bugs": "https://github.com/rotaready/moment-range/issues",
2929
"main": "./dist/moment-range",
30-
"version": "4.0.1",
30+
"version": "4.0.2",
3131
"engines": {
3232
"node": "*"
3333
},
@@ -36,15 +36,15 @@
3636
],
3737
"scripts": {
3838
"build": "webpack -p",
39-
"check": "yarn run check:flow && yarn run check:typescript",
39+
"check": "yarn check:flow && yarn check:typescript",
4040
"check:flow": "flow",
4141
"check:typescript": "tsc --project ./typing-tests/typescript",
4242
"doctoc": "doctoc README.md --github",
4343
"lint": "eslint ./lib/",
44-
"prepublishOnly": "yarn run build && cp ./lib/*.flow ./lib/*.d.ts ./dist",
45-
"preversion": "yarn run check && yarn run lint && yarn run test",
44+
"prepublishOnly": "yarn build && cp ./lib/*.flow ./lib/*.d.ts ./dist",
45+
"preversion": "yarn check && yarn lint && yarn test",
4646
"test": "karma start ./karma.conf.js",
47-
"version": "yarn run build && cp ./lib/*.flow ./lib/*.d.ts ./dist"
47+
"version": "yarn build && cp ./lib/*.flow ./lib/*.d.ts ./dist"
4848
},
4949
"typings": "./dist/moment-range.d.ts",
5050
"devDependencies": {
@@ -55,7 +55,7 @@
5555
"babel-polyfill": "^6.16.0",
5656
"babel-preset-es2015": "^6.18.0",
5757
"babel-preset-stage-0": "^6.16.0",
58-
"doctoc": "^1.2.0",
58+
"doctoc": "^1.4.0",
5959
"eslint": "^3.11.1",
6060
"eslint-loader": "^1.6.1",
6161
"expect.js": "^0.3.1",
@@ -70,7 +70,7 @@
7070
"karma-webpack": "^2.0.2",
7171
"mocha": "^2.5.3",
7272
"moment": "^2.17.1",
73-
"typescript": "^2.6.2",
73+
"typescript": "^3.3.3333",
7474
"webpack": "^2.2.1"
7575
},
7676
"peerDependencies": {

typing-tests/flow/moment-range.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ const moment = extendMoment(M);
1111

1212
moment.range(new Date(), new Date());
1313
moment.range(moment(), moment());
14+
moment.range(moment(), new Date());
15+
moment.range(new Date(), moment());
1416
moment.range([new Date(), new Date()]);
1517
moment.range([moment(), moment()]);
18+
moment.range([moment(), new Date()]);
19+
moment.range([new Date(), moment()]);
1620
moment.range('year');
21+
moment.range();
1722

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

2934
new DateRange(new Date(), new Date());
3035
new DateRange(moment(), moment());
36+
new DateRange(moment(), new Date());
37+
new DateRange(new Date(), moment());
3138
new DateRange([new Date(), new Date()]);
3239
new DateRange([moment(), moment()]);
40+
new DateRange([moment(), new Date()]);
41+
new DateRange([new Date(), moment()]);
3342
new DateRange('year');
43+
new DateRange();
3444

3545
// Adjacent
3646
const range001 = new DateRange('year');

0 commit comments

Comments
 (0)