Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.
TypeScript albumsexif-extractiongeocodinglive-photomotion-photophoto-galleryphoto-sharingwebgl-viewer
export type AnalyticsDateRange = {
from: string
to: string
preset?: number
allTime?: boolean
}
export const ANALYTICS_PRESETS = [
1800, 3600, 21600, 43200, 86400, 604800, 2592000,
] as const
export function analyticsYearBoundary(now = Date.now()) {
const date = new Date(now)
return Date.UTC(
date.getUTCFullYear() - 1,
date.getUTCMonth(),
date.getUTCDate(),
)
}
export function relativeRange(
seconds: number,
now = Date.now(),
): AnalyticsDateRange {
now = Math.floor(now / 60000) * 60000
return {
from: new Date(now - seconds * 1000).toISOString(),
to: new Date(now).toISOString(),
preset: seconds,
}
}
// Daily archives cannot represent partial days; preserve half-open end semantics.
export function archiveRange(
range: AnalyticsDateRange,
now = Date.now(),
): AnalyticsDateRange {
const start = Date.parse(range.from),
end = Date.parse(range.to)
if (
range.allTime ||
(end - start <= 31 * 86400000 && start >= now - 89 * 86400000)
)
return range
return {
...range,
from: new Date(start).toISOString().slice(0, 10),
to: new Date(end - 1).toISOString().slice(0, 10),
}
}
export function rangeInput(value: string, utc: boolean) {
const date = new Date(value)
return new Date(date.getTime() - (utc ? 0 : date.getTimezoneOffset() * 60000))
.toISOString()
.slice(0, 16)
}
export function inputInstant(value: string, utc: boolean) {
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/.test(value)) return NaN
return Date.parse(value + (utc ? ':00Z' : ':00'))
}