-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
51 lines (42 loc) · 1.48 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
export async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
export function sleepUntil(date) {
const timeToWait = Math.max(0, date.getTime() - Date.now())
return sleep(timeToWait)
}
// Given a date and a timezone, return the date in YYYY-MM-DD format
//
// Example: new Date(), "America/Los_Angeles" -> "2025-01-23"
export function yyyymmddLocalTimezone(date, timezone) {
if (!(date instanceof Date)) {
date = new Date(date)
}
const parts = date.toLocaleString('en-US', {
timeZone: timezone,
year: 'numeric',
month: '2-digit',
day: '2-digit'
})
.split(',')[0]
.split('/')
// parts are in MM/DD/YYYY format
const [month, day, year] = parts
return `${year}-${month.padStart(2,'0')}-${day.padStart(2,'0')}`
}
// Given 2025-01-23 and 2025-01-25, return [2025-01-23, 2025-01-24, 2025-01-25]
export function daysBetweenYyymmdd(startDateStr, endDateStr) {
const days = []
const currentDate = new Date(startDateStr)
const endDate = new Date(endDateStr)
while (currentDate <= endDate) {
days.push(currentDate.toISOString().split('T')[0])
currentDate.setDate(currentDate.getDate() + 1)
}
return days
}
const flavortexts = await Bun.file('./flavortext.txt').text()
const flavortextLines = flavortexts.split('\n').filter(line => line.trim())
export function flavortext() {
return flavortextLines[Math.floor(Math.random() * flavortextLines.length)]
}