solar-time
Version:
This library provides functions to calculate local solar time, also known as local apparent time, based on a given location and date.
36 lines (35 loc) • 1.59 kB
TypeScript
/**
* Calculate day of year (1-365/366) using UTC date components.
* Uses UTC to ensure consistent calculations regardless of local timezone.
* @param date - Date to calculate day of year for
* @returns Day of year (1 = Jan 1, 365/366 = Dec 31)
*/
export declare function getDayOfYear(date: Date): number;
/**
* Get UTC offset in hours from ISO 8601 string with timezone
* @example getUTCOffset("2025-11-01T09:00:00+09:00") -> 9
* @example getUTCOffset("2025-11-01T09:00:00-05:00") -> -5
* @example getUTCOffset("2025-11-01T09:00:00Z") -> 0
*/
export declare function getUTCOffset(isoDateTime: string): number;
/**
* Get UTC midnight of the local date (accounting for timezone).
* Returns midnight for the local date as ISO string, not the UTC date.
* @param isoDateTime - ISO 8601 string with timezone
* @returns UTC midnight (00:00:00) of the local date as ISO string
*/
export declare function getUTCMidnight(isoDateTime: string): string;
/**
* Add minutes to an ISO 8601 datetime and return new ISO 8601 string
* Preserves timezone from input
* @param isoDateTime - Base ISO 8601 datetime string
* @param minutes - Minutes to add (can be negative)
* @param timezoneOffset - UTC offset in hours
*/
export declare function addMinutes(isoDateTime: string, minutes: number, timezoneOffset: number): string;
/**
* Get local time of day in minutes (0-1440), accounting for timezone.
* @param isoDateTime - ISO 8601 string with timezone
* @returns Minutes since midnight (0-1440 range)
*/
export declare function getLocalTimeInMinutes(isoDateTime: string): number;