{"id":24458257,"url":"https://github.com/imevanc/chronobox","last_synced_at":"2025-05-05T21:41:28.863Z","repository":{"id":273216324,"uuid":"918717495","full_name":"imevanc/chronobox","owner":"imevanc","description":"A TypeScript library for date manipulation","archived":false,"fork":false,"pushed_at":"2025-03-13T19:50:38.000Z","size":261,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-13T20:36:48.576Z","etag":null,"topics":["dates","jest","npm","prettier","semantic-release","ts-jest","ts-node","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imevanc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-18T17:13:48.000Z","updated_at":"2025-03-13T19:50:40.000Z","dependencies_parsed_at":"2025-02-13T20:23:14.035Z","dependency_job_id":"503fffb4-42d6-4b9b-ad2b-463c65b353b7","html_url":"https://github.com/imevanc/chronobox","commit_stats":null,"previous_names":["imevanc/date-wizard","imevanc/chronobox"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imevanc%2Fchronobox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imevanc%2Fchronobox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imevanc%2Fchronobox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imevanc%2Fchronobox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imevanc","download_url":"https://codeload.github.com/imevanc/chronobox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243482569,"owners_count":20297893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dates","jest","npm","prettier","semantic-release","ts-jest","ts-node","typescript"],"created_at":"2025-01-21T03:13:20.687Z","updated_at":"2025-05-05T21:41:28.855Z","avatar_url":"https://github.com/imevanc.png","language":"TypeScript","readme":"# ChronoBox\n\nChronoBox is a lightweight, versatile, and easy-to-use TypeScript library for handling date manipulation and formatting. It provides a powerful API for adding, subtracting, comparing, and formatting dates.\n\n## 🚀 Features\n\n- Add and subtract time units (e.g., days, weeks, months, years) with ease\n- Calculate differences between dates in various time units\n- Retrieve individual components of a date\n- Format dates using custom formats\n- Built-in validation for date inputs\n- Fully written in TypeScript with strong type safety\n\n## 📦 Installation\n\n```bash\nnpm install chronobox\n```\n\n## 📖 API Reference\n### ChronoBox\nThe ChronoBox class provides a convenient and powerful API for date manipulation, formatting, and validation.\n\n### Constructor\n```typescript\nnew ChronoBox\u003cTFormat extends DateFormat | CustomFormat = DateFormat\u003e(date?: DateInput, format?: TFormat)\n```\n- date (optional): The date to initialize the ChronoBox instance. If not provided, the current date and time will be used.\n- format (optional): The format for the date output. Defaults to DateFormat.ISO.\n\n### Methods\n```typescript\nadd\u003cT extends TimeUnit\u003e(amount: number, unit: T): ChronoBox\u003cTFormat\u003e\n```\nAdds a specified amount of time to the current date.\n\n- amount: The amount of time to add.\n- unit: The unit of time to add (e.g., TimeUnit.DAYS, TimeUnit.MONTHS, etc.).\n- returns: A new ChronoBox instance with the updated date.\n---\n```typescript\nsubtract\u003cT extends TimeUnit\u003e(amount: number, unit: T): ChronoBox\u003cTFormat\u003e\n```\nSubtracts a specified amount of time from the current date.\n\n- amount: The amount of time to subtract.\n- unit: The unit of time to subtract.\n- returns: A new ChronoBox instance with the updated date.\n---\n```typescript\ndiff(other: DateInput, unit: TimeUnit = TimeUnit.DAYS): number\n```\nCalculates the difference between the current date and another date in the specified time unit.\n\n- other: The other date to compare with.\n- unit: The unit of time for the difference (e.g., TimeUnit.DAYS, TimeUnit.MONTHS, etc.).\n- returns: The difference in the specified time unit.\n---\n```typescript\ngetComponents(): DateComponents\n```\nReturns the individual components (year, month, day, hours, minutes, seconds, milliseconds) of the date.\n\n- returns: An object with the above structure.\n\n---\n\n```typescript\nformatDate(): string\n```\nFormats the current date according to the specified format.\n\n- returns: A string representation of the date based on the format.\n---\n```typescript\nisValid(): boolean\n```\nChecks whether the current date is valid.\n\n- returns: true if the date is valid, otherwise false.\n---\n```typescript\ntoDate(): Date\n```\nReturns the underlying Date object from the ChronoBox instance.\n\n- returns: A Date object representing the current date.\n\n---\n```typescript\nwithFormat\u003cNewFormat extends DateFormat | CustomFormat\u003e(newFormat: NewFormat): ChronoBox\u003cNewFormat\u003e\n```\n\nCreates a new ChronoBox instance with a different format.\n\n- newFormat: The new format for the date.\n- returns: A new ChronoBox instance with the updated format.\n\n---\n```typescript\nisAfter(other: DateInput, granularity: TimeUnit = TimeUnit.MILLISECONDS): boolean\n```\n\nChecks if this date is after the specified date.\n- other: The date to compare against.\n- granularity: The time unit granularity for comparison (defaults to milliseconds for exact comparison).\n- returns: true if this date is after the specified date.\n\n\n---\n```typescript\nisBefore(other: DateInput, granularity: TimeUnit = TimeUnit.MILLISECONDS): boolean\n```\n\nChecks if this date is before the specified date.\n- other: The date to compare against.\n- granularity: The time unit granularity for comparison (defaults to milliseconds for exact comparison).\n- returns: true if this date is before the specified date.\n\n---\n```typescript\nconvertTimezone(date: Date | ChronoBox, fromTimezone: string, toTimezone: string): Date\n```\n\nConverts a date from one timezone to another\n- date: The date to convert.\n- fromTimezone: The source timezone (e.g., 'America/New_York').\n- toTimezone: The target timezone (e.g., 'Europe/London').\n- returns: A new Date object representing the same moment in the target timezone.\n\n---\n```typescript\ngetTimezoneOffsetMinutes(date: Date | ChronoBox, timezone: string): number\n```\n\nGets the timezone offset in minutes for a date in a specific timezone.\n- date: The date to get the offset for.\n- timezone: The timezone to get the offset for (e.g., 'America/New_York').\n- returns: The timezone offset in minutes (positive for timezones behind UTC, negative for timezones ahead of UTC).\n\n---\n```typescript\nisInDST(date: Date | ChronoBox, timezone: string): boolean\n```\n\nChecks if a date is in Daylight Saving Time (DST) for a specific timezone.\n- date: The date to check.\n- timezone: The timezone to check for DST (e.g., 'America/New_York').\n- returns: true if the date is in DST for the specified timezone, false otherwise.\n\n---\n```typescript\nfindDSTTransitions(year: number, timezone: string): { start: Date | null; end: Date | null }\n```\n\nFinds the exact DST transition times for a given year in a specific timezone.\n- year: The year to find DST transitions for.\n- timezone: The timezone to check (e.g., 'America/New_York').\n- returns: An object with start and end properties containing the DST transition dates, or null if no DST.\n\n---\n```typescript\nstartOf\u003cT extends TimeUnit\u003e(unit: T): ChronoBox\u003cTFormat\u003e\n```\n\nGets the start of a specified time unit for the current date.\n- unit: The time unit to get the start of (e.g., day, hour, minute).\n- Returns: A new ChronoBox instance set to the start of the specified unit.\n\n---\n```typescript\nendOf\u003cT extends TimeUnit\u003e(unit: T): ChronoBox\u003cTFormat\u003e\n```\nGets the end of a specified time unit for the current date.\n- unit: The time unit to get the end of (e.g., day, hour, minute).\n- Returns: A new ChronoBox instance set to the end of the specified unit.\n\n---\n```typescript\nfromNow(referenceDate?: DateInput): string\n```\nGets a human-readable string representing the time difference between the current date and now.\n- referenceDate?: An optional date to compare against. Defaults to the current time.\n- Returns: A string representing the relative time difference, e.g., \"5 minutes ago\", \"in 2 days\".\n\n## 📄 License\nChronoBox is open-source software, licensed under the [MIT License](LICENSE).\n\n## ❤️ Support\nIf you find ChronoBox helpful, please give it a ⭐️ on GitHub and share it with your fellow developers!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimevanc%2Fchronobox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimevanc%2Fchronobox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimevanc%2Fchronobox/lists"}