my-bluesky-data
Version:
Connects to your Bluesky acocunt and creates HTML of your latest post for use on your webpage, with hourly cron job to get updates
39 lines (32 loc) • 1.32 kB
JavaScript
// takes a date string -> 2025-01-25T00:00:00.00Z
function ParseTimeStamp(timestamp) {
let date = new Date(timestamp);
let zoneAdjustedTime = convertUTCDateToLocalDate(date)
let dateparts = zoneAdjustedTime.split('T')
let yearmonthday = dateparts[0].split('-');
let monthdayyear = [yearmonthday[1], yearmonthday[2], yearmonthday[0]]
const monthNames = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
]
let monthtext = monthNames[parseInt(monthdayyear[0]) - 1] || 'Invalid month'
let daytext = monthdayyear[1].replace(/^0/, '') // Remove leading zero if present
let hourmins = dateparts[1].split(':')
let hour = parseInt(hourmins[0])
let minute = hourmins[1]
let am_pm = 'AM'
if (hour === 12) {
am_pm = 'PM'
} else if (hour > 12) {
hour -= 12
am_pm = 'PM'
}
let timetext = `${hour}:${minute}`
return `${monthtext} ${daytext}, ${monthdayyear[2]} at ${timetext} ${am_pm}`
}
function convertUTCDateToLocalDate(date) {
const offset = date.getTimezoneOffset();
const localDate = new Date(date.getTime() - offset * 60 * 1000)
return localDate.toISOString()
}
export {ParseTimeStamp}