@@ -17,51 +17,48 @@ export class PeriodicNotes extends DateBasedCollection {
17
17
/** The folder containing all of the notes. */
18
18
public readonly folder : string ;
19
19
20
- /**
21
- * Luxon format used to parse dates from the file's name.
22
- * @see {@link https://moment.github.io/luxon/#/parsing?id=table-of-tokens }
23
- */
20
+ /** @see {@link https://moment.github.io/luxon/#/parsing?id=table-of-tokens } */
24
21
public readonly dateFormat : string ;
25
22
26
- /**
27
- * Offset between the file's _parsed_ date and the corresponding {@link Interval}'s _start_ date. May be negative.
28
- * @example a periodic sprint log using ISO weeks, which start on Monday, as its {@link dateFormat} when sprints
29
- * _actually_ begin on Thursdays.
30
- */
31
- public readonly dateOffset : Duration < true > ;
23
+ /** Luxon options used when parsing {@link DateTime}s from file names. */
24
+ public readonly dateOptions : DateTimeOptions ;
32
25
33
26
/**
34
27
* The {@link Duration} of each file's corresponding {@link Interval}.
35
28
* @example a daily log's duration would be `{ days: 1 }`.
36
29
*/
37
30
public readonly intervalDuration : Duration < true > ;
38
31
39
- /** Luxon options used when parsing {@link DateTime}s from file names. */
40
- public readonly dateOptions : DateTimeOptions ;
32
+ /**
33
+ * Offset between the file's _parsed_ date and the corresponding {@link Interval}'s _start_ date. May be negative.
34
+ * @example a periodic sprint log using ISO weeks, which start on Monday, as its {@link dateFormat} when sprints
35
+ * _actually_ begin on Thursdays.
36
+ */
37
+ public readonly intervalOffset : Duration < true > ;
41
38
42
39
public constructor (
43
40
folder : string ,
44
41
dateFormat : string ,
45
42
intervalDurationLike : DurationLike ,
46
- dateOffsetLike : DurationLike = 0 ,
43
+ intervalOffsetLike : DurationLike = 0 ,
47
44
dateOptions : DateTimeOptions = { } ,
48
45
) {
49
46
super ( ) ;
50
47
51
- folder = folder . trim ( ) ;
52
- const dateOffset = Duration . fromDurationLike ( dateOffsetLike ) ;
48
+ folder = folder . trim ( ) . replace ( / \/ $ / , "" ) ; // Ensure trailing slashes are removed.
49
+ const intervalOffset = Duration . fromDurationLike ( intervalOffsetLike ) ;
53
50
const intervalDuration = Duration . fromDurationLike ( intervalDurationLike ) ;
54
51
55
52
assert ( folder . length > 0 , "folder must be non-empty" ) ;
56
53
assert ( dateFormat . length > 0 , "dateFormat must be non-empty" ) ;
57
- assert ( dateOffset . isValid , "dateOffset must be valid" ) ;
54
+ assert ( intervalOffset . isValid , "dateOffset must be valid" ) ;
58
55
assert ( intervalDuration . isValid && intervalDuration . valueOf ( ) !== 0 , "intervalDuration must be non-zero" ) ;
59
56
60
57
this . folder = folder ;
61
58
this . dateFormat = dateFormat ;
62
- this . dateOffset = dateOffset ;
63
- this . intervalDuration = intervalDuration ;
64
59
this . dateOptions = dateOptions ;
60
+ this . intervalDuration = intervalDuration ;
61
+ this . intervalOffset = intervalOffset ;
65
62
}
66
63
67
64
/**
@@ -70,14 +67,14 @@ export class PeriodicNotes extends DateBasedCollection {
70
67
* @returns the {@link Interval} corresponding to the file, otherwise an invalid interval.
71
68
*/
72
69
public override getIntervalOf ( filePath : string ) : IntervalMaybeValid {
73
- const path = parse ( filePath ) ;
74
- if ( path . dir !== this . folder ) {
75
- return Interval . invalid ( ` invalid interval folder` , `"${ filePath } " is not in "${ this . folder } "` ) ;
70
+ const parsedPath = parse ( filePath ) ;
71
+ if ( parsedPath . dir !== this . folder ) {
72
+ return Interval . invalid ( " invalid folder" , `"${ filePath } " is not in "${ this . folder } "` ) ;
76
73
}
77
- const date = DateTime . fromFormat ( path . name , this . dateFormat , this . dateOptions ) ;
78
- if ( ! date . isValid ) {
79
- return Interval . invalid ( ` invalid interval filename` , `${ date . invalidReason } ${ date . invalidExplanation } ` ) ;
74
+ const parsedDate = DateTime . fromFormat ( parsedPath . name , this . dateFormat , this . dateOptions ) ;
75
+ if ( ! parsedDate . isValid ) {
76
+ return Interval . invalid ( " invalid filename" , `${ parsedDate . invalidReason } ${ parsedDate . invalidExplanation } ` ) ;
80
77
}
81
- return Interval . after ( date . plus ( this . dateOffset ) , this . intervalDuration ) ;
78
+ return Interval . after ( parsedDate . plus ( this . intervalOffset ) , this . intervalDuration ) ;
82
79
}
83
80
}
0 commit comments