@kalender/core
Advanced tools
Comparing version 0.3.3-alpha.0 to 0.3.3-alpha.1
@@ -24,5 +24,7 @@ import { WeekDay } from './definition'; | ||
export declare function normalDate(year: number, month: number, day?: number): Date; | ||
export declare function date(year: number, month: number, day?: number): Date; | ||
export declare function dayOfYear(date: Date): number; | ||
export declare function addWeekDays(day: WeekDay, count: number): WeekDay; | ||
export declare function now(): Date; | ||
export declare function daysRemainOfMonth(date: Date): number; | ||
//# sourceMappingURL=date.d.ts.map |
@@ -5,63 +5,2 @@ 'use strict'; | ||
function isWorkDay(date) { | ||
const day = date.getDay(); | ||
return day >= 1 && day <= 5; | ||
} | ||
function isWeekend(date) { | ||
const day = date.getDay(); | ||
return day === 6 || day === 0; | ||
} | ||
function getWeekDay(date) { | ||
const day = date.getDay(); | ||
return day === 0 ? 7 : day; | ||
} | ||
function getMonth(date) { | ||
return date.getMonth() + 1; | ||
} | ||
function eraseTime(date) { | ||
const { year, month, day } = extract(date); | ||
return normalDate(year, month, day); | ||
} | ||
function extract(date) { | ||
return { | ||
year: date.getFullYear(), | ||
month: getMonth(date), | ||
day: date.getDate(), | ||
weekDay: getWeekDay(date), | ||
dayOfYear: dayOfYear(date), | ||
hour: date.getHours(), | ||
minute: date.getMinutes(), | ||
second: date.getSeconds(), | ||
}; | ||
} | ||
function extractDate(date) { | ||
return { | ||
year: date.getFullYear(), | ||
month: getMonth(date), | ||
day: date.getDate(), | ||
weekDay: getWeekDay(date), | ||
}; | ||
} | ||
function normalDate(year, month, day = 1) { | ||
return new Date(year, month - 1, day); | ||
} | ||
function dayOfYear(date) { | ||
const firstDay = normalDate(date.getFullYear(), 1, 1); | ||
return (date.valueOf() - firstDay.valueOf()) / 1000 / 3600 / 24 + 1; | ||
} | ||
function addWeekDays(day, count) { | ||
count = count % 7; | ||
day = day + count; | ||
if (day < 0) { | ||
day += 7; | ||
} | ||
if (day > 7) { | ||
day -= 7; | ||
} | ||
return day; | ||
} | ||
function now() { | ||
return new Date(); | ||
} | ||
(function (TimeUnits) { | ||
@@ -312,2 +251,77 @@ TimeUnits["Year"] = "Year"; | ||
function isWorkDay(date) { | ||
const day = date.getDay(); | ||
return day >= 1 && day <= 5; | ||
} | ||
function isWeekend(date) { | ||
const day = date.getDay(); | ||
return day === 6 || day === 0; | ||
} | ||
function getWeekDay(date) { | ||
const day = date.getDay(); | ||
return day === 0 ? 7 : day; | ||
} | ||
function getMonth(date) { | ||
return date.getMonth() + 1; | ||
} | ||
function eraseTime(date) { | ||
const { year, month, day } = extract(date); | ||
return normalDate(year, month, day); | ||
} | ||
function extract(date) { | ||
return { | ||
year: date.getFullYear(), | ||
month: getMonth(date), | ||
day: date.getDate(), | ||
weekDay: getWeekDay(date), | ||
dayOfYear: dayOfYear(date), | ||
hour: date.getHours(), | ||
minute: date.getMinutes(), | ||
second: date.getSeconds(), | ||
}; | ||
} | ||
function extractDate(date) { | ||
return { | ||
year: date.getFullYear(), | ||
month: getMonth(date), | ||
day: date.getDate(), | ||
weekDay: getWeekDay(date), | ||
}; | ||
} | ||
function normalDate(year, month, day = 1) { | ||
return new Date(year, month - 1, day); | ||
} | ||
function date(year, month, day = 1) { | ||
if (day > 0) { | ||
return normalDate(year, month, day); | ||
} | ||
const maxDay = daysOfMonth(year, month); | ||
if (day === 0) | ||
day = -1; | ||
return normalDate(year, month, day + maxDay + 1); | ||
} | ||
function dayOfYear(date) { | ||
const firstDay = normalDate(date.getFullYear(), 1, 1); | ||
return (date.valueOf() - firstDay.valueOf()) / 1000 / 3600 / 24 + 1; | ||
} | ||
function addWeekDays(day, count) { | ||
count = count % 7; | ||
day = day + count; | ||
if (day < 0) { | ||
day += 7; | ||
} | ||
if (day > 7) { | ||
day -= 7; | ||
} | ||
return day; | ||
} | ||
function now() { | ||
return new Date(); | ||
} | ||
function daysRemainOfMonth(date) { | ||
const { year, month, day } = extract(date); | ||
const days = daysOfMonth(year, month); | ||
return days - day; | ||
} | ||
function daysOfYear(year) { | ||
@@ -419,5 +433,9 @@ const start = normalDate(year, 1, 1); | ||
registerHandler(exports.RepeatTypes.MonthDay, (date, option) => { | ||
// support days counting from end of month: | ||
const daysRemain = daysRemainOfMonth(date); | ||
if (option.day + 1 !== daysRemain) | ||
return false; | ||
const thatDay = normalDate(option.start.getFullYear(), option.month, option.day); | ||
const { year, month, day } = diffTime(thatDay, eraseTime(date)); | ||
if (month !== 0 || day !== 0) | ||
const { year, month } = diffTime(thatDay, eraseTime(date)); | ||
if (month !== 0) | ||
return false; | ||
@@ -570,2 +588,3 @@ if (isDefined(option.interval) && | ||
exports.createEvents = createEvents; | ||
exports.date = date; | ||
exports.dayOfYear = dayOfYear; | ||
@@ -576,2 +595,3 @@ exports.daysBetween = daysBetween; | ||
exports.daysOfYear = daysOfYear; | ||
exports.daysRemainOfMonth = daysRemainOfMonth; | ||
exports.diff = diff; | ||
@@ -578,0 +598,0 @@ exports.diffTime = diffTime; |
@@ -1,62 +0,1 @@ | ||
function isWorkDay(date) { | ||
const day = date.getDay(); | ||
return day >= 1 && day <= 5; | ||
} | ||
function isWeekend(date) { | ||
const day = date.getDay(); | ||
return day === 6 || day === 0; | ||
} | ||
function getWeekDay(date) { | ||
const day = date.getDay(); | ||
return day === 0 ? 7 : day; | ||
} | ||
function getMonth(date) { | ||
return date.getMonth() + 1; | ||
} | ||
function eraseTime(date) { | ||
const { year, month, day } = extract(date); | ||
return normalDate(year, month, day); | ||
} | ||
function extract(date) { | ||
return { | ||
year: date.getFullYear(), | ||
month: getMonth(date), | ||
day: date.getDate(), | ||
weekDay: getWeekDay(date), | ||
dayOfYear: dayOfYear(date), | ||
hour: date.getHours(), | ||
minute: date.getMinutes(), | ||
second: date.getSeconds(), | ||
}; | ||
} | ||
function extractDate(date) { | ||
return { | ||
year: date.getFullYear(), | ||
month: getMonth(date), | ||
day: date.getDate(), | ||
weekDay: getWeekDay(date), | ||
}; | ||
} | ||
function normalDate(year, month, day = 1) { | ||
return new Date(year, month - 1, day); | ||
} | ||
function dayOfYear(date) { | ||
const firstDay = normalDate(date.getFullYear(), 1, 1); | ||
return (date.valueOf() - firstDay.valueOf()) / 1000 / 3600 / 24 + 1; | ||
} | ||
function addWeekDays(day, count) { | ||
count = count % 7; | ||
day = day + count; | ||
if (day < 0) { | ||
day += 7; | ||
} | ||
if (day > 7) { | ||
day -= 7; | ||
} | ||
return day; | ||
} | ||
function now() { | ||
return new Date(); | ||
} | ||
var TimeUnits; | ||
@@ -310,2 +249,77 @@ (function (TimeUnits) { | ||
function isWorkDay(date) { | ||
const day = date.getDay(); | ||
return day >= 1 && day <= 5; | ||
} | ||
function isWeekend(date) { | ||
const day = date.getDay(); | ||
return day === 6 || day === 0; | ||
} | ||
function getWeekDay(date) { | ||
const day = date.getDay(); | ||
return day === 0 ? 7 : day; | ||
} | ||
function getMonth(date) { | ||
return date.getMonth() + 1; | ||
} | ||
function eraseTime(date) { | ||
const { year, month, day } = extract(date); | ||
return normalDate(year, month, day); | ||
} | ||
function extract(date) { | ||
return { | ||
year: date.getFullYear(), | ||
month: getMonth(date), | ||
day: date.getDate(), | ||
weekDay: getWeekDay(date), | ||
dayOfYear: dayOfYear(date), | ||
hour: date.getHours(), | ||
minute: date.getMinutes(), | ||
second: date.getSeconds(), | ||
}; | ||
} | ||
function extractDate(date) { | ||
return { | ||
year: date.getFullYear(), | ||
month: getMonth(date), | ||
day: date.getDate(), | ||
weekDay: getWeekDay(date), | ||
}; | ||
} | ||
function normalDate(year, month, day = 1) { | ||
return new Date(year, month - 1, day); | ||
} | ||
function date(year, month, day = 1) { | ||
if (day > 0) { | ||
return normalDate(year, month, day); | ||
} | ||
const maxDay = daysOfMonth(year, month); | ||
if (day === 0) | ||
day = -1; | ||
return normalDate(year, month, day + maxDay + 1); | ||
} | ||
function dayOfYear(date) { | ||
const firstDay = normalDate(date.getFullYear(), 1, 1); | ||
return (date.valueOf() - firstDay.valueOf()) / 1000 / 3600 / 24 + 1; | ||
} | ||
function addWeekDays(day, count) { | ||
count = count % 7; | ||
day = day + count; | ||
if (day < 0) { | ||
day += 7; | ||
} | ||
if (day > 7) { | ||
day -= 7; | ||
} | ||
return day; | ||
} | ||
function now() { | ||
return new Date(); | ||
} | ||
function daysRemainOfMonth(date) { | ||
const { year, month, day } = extract(date); | ||
const days = daysOfMonth(year, month); | ||
return days - day; | ||
} | ||
function daysOfYear(year) { | ||
@@ -418,5 +432,9 @@ const start = normalDate(year, 1, 1); | ||
registerHandler(RepeatTypes.MonthDay, (date, option) => { | ||
// support days counting from end of month: | ||
const daysRemain = daysRemainOfMonth(date); | ||
if (option.day + 1 !== daysRemain) | ||
return false; | ||
const thatDay = normalDate(option.start.getFullYear(), option.month, option.day); | ||
const { year, month, day } = diffTime(thatDay, eraseTime(date)); | ||
if (month !== 0 || day !== 0) | ||
const { year, month } = diffTime(thatDay, eraseTime(date)); | ||
if (month !== 0) | ||
return false; | ||
@@ -560,3 +578,3 @@ if (isDefined(option.interval) && | ||
export { RepeatTypes, TimeUnits, WeekDay, WeekDays, WeekendDays, WorkDays, addDays, addMonths, addWeekDays, addWeeks, createEvent, createEvents, dayOfYear, daysBetween, daysOf, daysOfMonth, daysOfYear, diff, diffTime, eraseTime, extract, extractDate, getCalendarDay, getCalendarMonth, getCalendarMonthDates, getCalendarWeek, getCalendarWeekDates, getDefault, getMonth, getMonthDates, getWeekDay, increaseSign, isDefined, isEventMatch, isInt, isNthWeekDay, isNum, isPositiveInt, isWeekDay, isWeekend, isWorkDay, lastOf, normalDate, now, nthWeekDay, parseEvents, range, registerHandler, setupHandlers, theFirstWeekDay, theLastWeekDay, theNthWeekDay, toPositiveInt, weekDayFilter, weekDaysBetween, weekendDaysBetween, weeksBetween, weeksOf, workDaysBetween }; | ||
export { RepeatTypes, TimeUnits, WeekDay, WeekDays, WeekendDays, WorkDays, addDays, addMonths, addWeekDays, addWeeks, createEvent, createEvents, date, dayOfYear, daysBetween, daysOf, daysOfMonth, daysOfYear, daysRemainOfMonth, diff, diffTime, eraseTime, extract, extractDate, getCalendarDay, getCalendarMonth, getCalendarMonthDates, getCalendarWeek, getCalendarWeekDates, getDefault, getMonth, getMonthDates, getWeekDay, increaseSign, isDefined, isEventMatch, isInt, isNthWeekDay, isNum, isPositiveInt, isWeekDay, isWeekend, isWorkDay, lastOf, normalDate, now, nthWeekDay, parseEvents, range, registerHandler, setupHandlers, theFirstWeekDay, theLastWeekDay, theNthWeekDay, toPositiveInt, weekDayFilter, weekDaysBetween, weekendDaysBetween, weeksBetween, weeksOf, workDaysBetween }; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@kalender/core", | ||
"version": "0.3.3-alpha.0", | ||
"version": "0.3.3-alpha.1", | ||
"description": "calendar core library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
import { WeekDay } from './definition'; | ||
import { daysOfMonth } from './month'; | ||
@@ -53,2 +54,11 @@ export function isWorkDay(date: Date) { | ||
export function date(year: number, month: number, day: number = 1) { | ||
if (day > 0) { | ||
return normalDate(year, month, day); | ||
} | ||
const maxDay = daysOfMonth(year, month); | ||
if (day === 0) day = -1; | ||
return normalDate(year, month, day + maxDay + 1); | ||
} | ||
export function dayOfYear(date: Date) { | ||
@@ -75,1 +85,7 @@ const firstDay = normalDate(date.getFullYear(), 1, 1); | ||
} | ||
export function daysRemainOfMonth(date: Date) { | ||
const { year, month, day } = extract(date); | ||
const days = daysOfMonth(year, month); | ||
return days - day; | ||
} |
import { | ||
daysBetween, | ||
daysOfMonth, | ||
daysRemainOfMonth, | ||
diffTime, | ||
@@ -86,23 +87,28 @@ eraseTime, | ||
registerHandler(RepeatTypes.MonthDay, (date, option) => { | ||
const thatDay = normalDate( | ||
option.start.getFullYear(), | ||
option.month, | ||
option.day | ||
); | ||
const { year, month, day } = diffTime(thatDay, eraseTime(date)); | ||
if (month !== 0 || day !== 0) return false; | ||
if ( | ||
isDefined(option.interval) && | ||
(year - (thatDay < eraseTime(option.start) ? 1 : 0)) % | ||
option.interval !== | ||
0 | ||
) | ||
return false; | ||
if ( | ||
isDefined(option.times) && | ||
year + (thatDay < eraseTime(option.start) ? 0 : 1) > | ||
getDefault(option.interval, 1) * option.times | ||
) | ||
return false; | ||
return true; | ||
// support days counting from end of month: | ||
const daysRemain = daysRemainOfMonth(date); | ||
if (option.day + 1 !== daysRemain) return false; | ||
const thatDay = normalDate( | ||
option.start.getFullYear(), | ||
option.month, | ||
option.day | ||
); | ||
const { year, month } = diffTime(thatDay, eraseTime(date)); | ||
if (month !== 0) return false; | ||
if ( | ||
isDefined(option.interval) && | ||
(year - (thatDay < eraseTime(option.start) ? 1 : 0)) % | ||
option.interval !== | ||
0 | ||
) | ||
return false; | ||
if ( | ||
isDefined(option.times) && | ||
year + (thatDay < eraseTime(option.start) ? 0 : 1) > | ||
getDefault(option.interval, 1) * option.times | ||
) | ||
return false; | ||
return true; | ||
}); | ||
@@ -109,0 +115,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
173661
2248