{"id":20806102,"url":"https://github.com/dgtlss/chronos","last_synced_at":"2026-02-17T03:10:16.500Z","repository":{"id":255265232,"uuid":"827736622","full_name":"dgtlss/chronos","owner":"dgtlss","description":"Chronos is a lightweight, timezone-aware date and time manipulation library for JavaScript. It provides an intuitive API for parsing, manipulating, and formatting dates and times.","archived":false,"fork":false,"pushed_at":"2024-09-02T18:44:37.000Z","size":60,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-03T08:47:39.609Z","etag":null,"topics":["chronos","chronosjs","date-formatting","date-manipulation","javascript","javascript-library","time-manipulation","vanilla-javascript","vanilla-js"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dgtlss.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2024-07-12T09:09:21.000Z","updated_at":"2024-09-02T18:45:04.000Z","dependencies_parsed_at":"2025-05-07T04:38:56.031Z","dependency_job_id":null,"html_url":"https://github.com/dgtlss/chronos","commit_stats":null,"previous_names":["dgtlss/chronos"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dgtlss/chronos","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgtlss%2Fchronos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgtlss%2Fchronos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgtlss%2Fchronos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgtlss%2Fchronos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgtlss","download_url":"https://codeload.github.com/dgtlss/chronos/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgtlss%2Fchronos/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007599,"owners_count":26084334,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["chronos","chronosjs","date-formatting","date-manipulation","javascript","javascript-library","time-manipulation","vanilla-javascript","vanilla-js"],"created_at":"2024-11-17T19:18:11.335Z","updated_at":"2025-10-11T15:38:15.545Z","avatar_url":"https://github.com/dgtlss.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chronos\n\nChronos is a powerful and user-friendly JavaScript library for working with dates and times. It provides an intuitive API for parsing, manipulating, and formatting dates, making it easier to handle complex date-related operations in your projects.\n\n## Getting Started\n\nTo use Chronos in your project, include the `chronos.min.js` file in your HTML:\n\n```html\n\u003cscript src=\"path/to/chronos.min.js\"\u003e\u003c/script\u003e\n```\n\n## Creating a Chronos Object\n\nYou can create a new Chronos object in several ways:\n\n```javascript\n// Current date and time\nconst now = new Chronos();\n\n// From a date string\nconst date = new Chronos('2023-05-15T12:00:00Z');\n\n// From a timestamp (milliseconds since epoch)\nconst timestamp = new Chronos(1684152000000);\n\n// With a specific timezone\nconst tokyoDate = new Chronos('2023-05-15T12:00:00Z', 'Asia/Tokyo');\n```\n\n## Core Methods\n\n### Getter Methods\n\nThese methods return specific parts of the date:\n\n- `year()`: Returns the year (e.g., 2023)\n- `month()`: Returns the month (1-12)\n- `date()`: Returns the day of the month (1-31)\n- `day()`: Returns the day of the week (0-6, where 0 is Sunday)\n- `hours()`: Returns the hour (0-23)\n- `minutes()`: Returns the minutes (0-59)\n- `seconds()`: Returns the seconds (0-59)\n- `milliseconds()`: Returns the milliseconds (0-999)\n- `timestamp()`: Returns the Unix timestamp (seconds since epoch)\n\nExample:\n```javascript\nconst date = new Chronos('2023-05-15T12:30:45Z');\nconsole.log(date.year());  // 2023\nconsole.log(date.month()); // 5\nconsole.log(date.date());  // 15\n```\n\n### Manipulation Methods\n\nThese methods allow you to modify the date:\n\n- `add(value, unit)`: Adds a specified amount of time\n- `subtract(value, unit)`: Subtracts a specified amount of time\n\nUnits can be: 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds'\n\nExample:\n```javascript\nconst date = new Chronos('2023-05-15T12:00:00Z');\nconsole.log(date.add(1, 'day').format('YYYY-MM-DD')); // 2023-05-16\nconsole.log(date.subtract(2, 'hours').format('YYYY-MM-DD HH:mm')); // 2023-05-15 10:00\n```\n\n### Formatting Methods\n\n- `format(formatString)`: Formats the date according to the specified format string\n- `translatedFormat(formatString, translations)`: Formats the date with translated month and day names\n\nFormat tokens:\n- `YYYY`: 4-digit year\n- `MM`: 2-digit month\n- `DD`: 2-digit day of month\n- `HH`: 2-digit hour (24-hour format)\n- `mm`: 2-digit minutes\n- `ss`: 2-digit seconds\n\nExample:\n```javascript\nconst date = new Chronos('2023-05-15T12:30:45Z');\nconsole.log(date.format('YYYY-MM-DD HH:mm:ss')); // 2023-05-15 12:30:45\n```\n\n### Comparison Methods\n\nThese methods allow you to compare dates:\n\n- `isBefore(other)`: Checks if the date is before another date\n- `isAfter(other)`: Checks if the date is after another date\n- `isSame(other)`: Checks if the date is the same as another date\n- `isBetween(start, end)`: Checks if the date is between two other dates\n- `isSameDay(other)`: Checks if the date is on the same day as another date\n- `isSameMonth(other)`: Checks if the date is in the same month as another date\n- `isSameYear(other)`: Checks if the date is in the same year as another date\n\nExample:\n```javascript\nconst date1 = new Chronos('2023-05-15T12:00:00Z');\nconst date2 = new Chronos('2023-05-16T12:00:00Z');\nconsole.log(date1.isBefore(date2)); // true\nconsole.log(date1.isSameDay(date2)); // false\n```\n\n### Utility Methods\n\nThese methods provide additional information about the date:\n\n- `isWeekday()`: Checks if the date is a weekday (Monday-Friday)\n- `isWeekend()`: Checks if the date is a weekend (Saturday or Sunday)\n- `isToday()`: Checks if the date is today\n- `isTomorrow()`: Checks if the date is tomorrow\n- `isYesterday()`: Checks if the date is yesterday\n- `isFuture()`: Checks if the date is in the future\n- `isPast()`: Checks if the date is in the past\n- `isLeapYear()`: Checks if the year is a leap year\n- `quarter()`: Returns the quarter of the year (1-4)\n\nExample:\n```javascript\nconst date = new Chronos('2023-05-15T12:00:00Z');\nconsole.log(date.isWeekday()); // true\nconsole.log(date.isLeapYear()); // false\n```\n\n### Conversion Methods\n\nThese methods convert the Chronos object to other formats:\n\n- `toDate()`: Converts to a JavaScript Date object\n- `valueOf()`: Returns the timestamp in milliseconds\n- `toString()`: Returns the date as an ISO string\n- `toJSON()`: Returns the date in JSON format\n- `toArray()`: Returns the date components as an array\n- `toObject()`: Returns the date components as an object\n\nExample:\n```javascript\nconst date = new Chronos('2023-05-15T12:00:00Z');\nconsole.log(date.toArray()); // [2023, 5, 15, 12, 0, 0, 0]\nconsole.log(date.toObject()); // { year: 2023, month: 5, day: 15, ... }\n```\n\n### Advanced Methods\n\n- `diffForHumans(other, options)`: Returns a human-readable difference between dates\n- `duration(other)`: Calculates the duration between two dates\n- `addBusinessDays(days)`: Adds a number of business days to the date\n- `startOf(unit)`: Returns the start of a unit of time (year, month, day, hour)\n- `endOf(unit)`: Returns the end of a unit of time (year, month, day, hour)\n\nExample:\n```javascript\nconst date1 = new Chronos('2023-05-15T12:00:00Z');\nconst date2 = new Chronos('2023-05-20T12:00:00Z');\nconsole.log(date1.diffForHumans(date2)); // 5 days ago\nconsole.log(date1.duration(date2)); // { days: 5, hours: 0, minutes: 0, seconds: 0 }\n```\n\n## Static Methods\n\nThese methods are called on the Chronos class itself:\n\n- `Chronos.now(timezone)`: Returns a Chronos object for the current date and time\n- `Chronos.parse(input, timezone)`: Parses a date string or timestamp\n- `Chronos.createFromFormat(format, dateString)`: Creates a Chronos object from a specific date format\n- `Chronos.createFromTimestamp(timestamp)`: Creates a Chronos object from a Unix timestamp\n- `Chronos.createFromTimestampMs(timestampMs)`: Creates a Chronos object from a timestamp in milliseconds\n- `Chronos.generateCalendar(year, month)`: Generates a calendar array for a given year and month\n\nExample:\n```javascript\nconst now = Chronos.now();\nconst parsed = Chronos.parse('2023-05-15T12:00:00Z');\nconst calendar = Chronos.generateCalendar(2023, 5);\n```\n\n## Contributing\n\nWe welcome contributions to Chronos! If you have any suggestions or improvements, please feel free to submit a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgtlss%2Fchronos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgtlss%2Fchronos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgtlss%2Fchronos/lists"}