0.1.4 • Published 8 years ago

baats-ymd v0.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

Baats YMD - BAATS (Baavgai's TypeScript) Library

Simple day representation for simple programs.

The design goal here is to give a day represention that's easy to bind to in things like React. Immutablity, also a plus. Don't need the time, just the day.
Also, to be honest, I find Date confusing, as month is zero indexed and day isn't and it's always bugged me. The getDate() for day is also less than intuative.

More to come, maybe

Just thinking out loud here. This is currently mostly for me, but it needs somewhere to live.

At the most basic level, a calendar day is represented as:

interface IYearMonth {
  year: number; // note, can be negative
  month: number; // 1..12
}

interface IYearMonthDay extends IYearMonth {
  day: number;
}

Functions all return something, there's no messing with your object:

isYm(x: any): x is IYearMonth;
isYmd(x: any): x is IYearMonthDay;
isDate(x: any): x is Date;
toDate(x: IYearMonthDay | IYearMonth): Date;
clone(x: IYearMonthDay): IYearMonthDay;
create(year: number, month: number, day: number): IYearMonthDay;
fromDate(x: Date): IYearMonthDay;
toYmd(year: number, month: number, day: number): IYearMonthDay;
toYmd(x?: any): IYearMonthDay;
toYm(year: number, month: number): IYearMonth;
toYm(x: any): IYearMonth;
addMonths(x: IYearMonth, months: number): IYearMonth;
isLeap(x: IYearMonth): boolean;
getDaysInMonth(x: IYearMonth): number;
compareDay(x: IYearMonthDay, y: IYearMonthDay): number;
weekday(x: IYearMonthDay): number;
addDays(x: IYearMonthDay, days: number): IYearMonthDay;
toJulianDayNum(x: IYearMonthDay): number;
fromJulianDayNum(julianDayNum: number): IYearMonthDay;
getMonthNames(): string[];
getMonthShortNames(): string[];
getDayNames(): string[];
getDayShortNames(): string[];
format(x: IYearMonthDay, mask?: string): string;

Julian day is the continuous count of days since the beginning of the Julian Period used primarily by astronomers.

The Julian Day Number (JDN) is the integer assigned to a whole solar day in the Julian day count starting from noon Greenwich Mean Time, with Julian day number 0 assigned to the day starting at ... November 24, 4714 BC, in the proleptic Gregorian calendar), a date at which three multi-year cycles started (which are: Indiction, Solar, and Lunar cycles) and which preceded any historical dates. For example, the Julian day number for the day starting at 12:00 UT on January 1, 2000, was 2,451,545.

-- https://en.wikipedia.org/wiki/Julian_day

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago