vremel
Version:
JavaScript date utility library for Temporal API
30 lines • 889 B
JavaScript
import { isPlainDate, isPlainYearMonth, isZonedDateTime, } from "../type-utils.js";
import { startOfTimeForZonedDateTime } from "./_startOfTimeForZonedDateTime.js";
/**
* Returns the start of a year for the given datetime
* @param dt datetime object which includes date info
* @returns Temporal object which represents the start of a year
*/
export function startOfYear(dt) {
if (isPlainYearMonth(dt)) {
return dt.with({ month: 1 });
}
if (isPlainDate(dt)) {
return dt.with({ month: 1, day: 1 });
}
const withArg = {
month: 1,
day: 1,
hour: 0,
minute: 0,
second: 0,
millisecond: 0,
microsecond: 0,
nanosecond: 0,
};
if (!isZonedDateTime(dt)) {
return dt.with(withArg);
}
return startOfTimeForZonedDateTime(dt, withArg);
}
//# sourceMappingURL=startOfYear.js.map