-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support monthly note navigation commands
- Loading branch information
1 parent
3464df8
commit 8a56b14
Showing
4 changed files
with
212 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import moment from "moment"; | ||
|
||
export function addMonthToDate(currentDate: moment.Moment): moment.Moment { | ||
let futureMonth = moment(currentDate).clone().add(1, "M"); | ||
const futureMonthEnd = moment(futureMonth).endOf("month"); | ||
|
||
if ( | ||
currentDate.date() != futureMonth.date() && | ||
futureMonth.isSame(futureMonthEnd.format("YYYY-MM-DD")) | ||
) { | ||
futureMonth = futureMonth.add(1, "d"); | ||
} | ||
|
||
return futureMonth; | ||
} | ||
|
||
export function subtractMonthFromDate( | ||
currentDate: moment.Moment | ||
): moment.Moment { | ||
let previousMonth = moment(currentDate).clone().subtract(1, "M"); | ||
const previousMonthBegin = moment(previousMonth).startOf("month"); | ||
|
||
if ( | ||
currentDate.date() != previousMonth.date() && | ||
previousMonth.isSame(previousMonthBegin.format("YYYY-MM-DD")) | ||
) { | ||
previousMonth = previousMonth.subtract(1, "d"); | ||
} | ||
|
||
return previousMonth; | ||
} |