-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issue with start time widget not registering tmr
- Loading branch information
Showing
2 changed files
with
50 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import moment from "moment"; | ||
|
||
/** | ||
* Gets some useful date booleans for a given date | ||
* @param date the date | ||
* @returns some useful date booleans like isTomorrow, isNextWeek, etc. | ||
*/ | ||
export function getUsefulDateBooleans(date: Date) { | ||
const isOverdue = moment().isAfter(date); | ||
const isToday = moment(date).isBetween( | ||
moment().startOf("day"), | ||
moment().endOf("day") | ||
); | ||
const lastDayOfWeek = moment().endOf("isoWeek"); | ||
const lastDayOfNextWeek = moment().add(1, "week").endOf("isoWeek"); | ||
const isThisWeek = moment(date).isBefore(lastDayOfWeek); | ||
const isNextWeek = | ||
moment(date).isAfter(lastDayOfWeek) && | ||
moment(date).isBefore(lastDayOfNextWeek); | ||
const beginningOfTmr = moment().add(1, "day").startOf("day"); | ||
const endOfTmr = moment().add(1, "day").endOf("day"); | ||
const isTomorrow = moment(date).isBetween(beginningOfTmr, endOfTmr); | ||
return { isOverdue, isToday, isThisWeek, isNextWeek, isTomorrow }; | ||
} | ||
|
||
/** | ||
* Our own version of a comprehensive English relative time formatter. Commonly used in the start time widget. | ||
* @param date start time / date | ||
* @returns string of the relative time | ||
*/ | ||
export function getEnglishDay(date: Date): string { | ||
const { isThisWeek, isToday, isOverdue, isTomorrow, isNextWeek } = | ||
getUsefulDateBooleans(date); | ||
|
||
const dateSection = isToday | ||
? "Today" | ||
: isOverdue | ||
? moment(date).fromNow() | ||
: isTomorrow | ||
? "Tomorrow" | ||
: isThisWeek | ||
? moment(date).format("dddd") | ||
: isNextWeek | ||
? "Next " + moment(date).format("dddd") | ||
: moment(date).format("MMM D"); | ||
return dateSection; | ||
} |
94c457b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
supernova-desktop-v2 – ./apps/desktop-v2
supernova-desktop-v2-trysupernova.vercel.app
supernova-desktop-v2.vercel.app
supernova-desktop-v2-git-main-trysupernova.vercel.app
web.trysupernova.one