-
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.
- Loading branch information
Showing
3 changed files
with
176 additions
and
6 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,23 @@ | ||
import { date, time } from "./format"; | ||
|
||
const checkDate = (start: Date) => { | ||
// Ensure we have a valid date | ||
if (isNaN(+start)) throw new Error("Invalid start date"); | ||
|
||
// If the date is in the past, we're fine | ||
if (start < new Date()) return null; | ||
|
||
// If we're within the same day, show the time | ||
if (start.getDate() === new Date().getDate()) { | ||
return `The Jingle Jam bundle hasn't launched yet! Get ready to raise money for some awesome causes and grab the bundle when it goes live at ${time( | ||
start, | ||
)}.`; | ||
} | ||
|
||
// Otherwise, show the date | ||
return `It's not currently Jingle Jam time. We look forward to seeing you on ${date( | ||
start, | ||
)} when we'll be back to raise money again!`; | ||
}; | ||
|
||
export default checkDate; |
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,43 @@ | ||
export const money = (currency: string, amount: number) => | ||
`${currency}${amount.toLocaleString(undefined, { | ||
minimumFractionDigits: 2, | ||
maximumFractionDigits: 2, | ||
})}`; | ||
|
||
export const date = (date: Date, time = false) => | ||
date.toLocaleString(undefined, { | ||
month: "long", | ||
day: "numeric", | ||
...(time && { | ||
hour: "numeric", | ||
minute: "numeric", | ||
timeZone: "GMT", | ||
timeZoneName: "short", | ||
}), | ||
}); | ||
|
||
export const time = (date: Date, seconds = false) => | ||
date.toLocaleString(undefined, { | ||
hour: "numeric", | ||
minute: "numeric", | ||
timeZone: "GMT", | ||
timeZoneName: "short", | ||
...(seconds && { | ||
second: "numeric", | ||
}), | ||
}); | ||
|
||
export const number = ( | ||
number: number, | ||
decimals: number | undefined = undefined, | ||
) => | ||
number.toLocaleString(undefined, { | ||
minimumFractionDigits: decimals, | ||
maximumFractionDigits: decimals, | ||
}); | ||
|
||
export const bold = (text: string, escape = true) => | ||
`**${escape ? text.replace(/\*/g, "\\*") : text}**`; | ||
|
||
export const italic = (text: string, escape = true) => | ||
`*${escape ? text.replace(/\*/g, "\\*") : text}*`; |