{"id":27946074,"url":"https://github.com/opensource-nepal/node-nepali-datetime","last_synced_at":"2025-05-07T13:47:55.896Z","repository":{"id":165605989,"uuid":"639942178","full_name":"opensource-nepal/node-nepali-datetime","owner":"opensource-nepal","description":"A Node project designed to support native JavaScript-like features for Nepali date and times. It includes features such as 'NepaliDate' for Nepali date support and 'dateConverter' for date conversions.","archived":false,"fork":false,"pushed_at":"2025-04-08T07:07:33.000Z","size":728,"stargazers_count":69,"open_issues_count":4,"forks_count":23,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-29T16:52:18.815Z","etag":null,"topics":["ad-to-bs","bs-to-ad","javascript","nepal","nepali","nepali-date","nepali-date-conversion","nepali-date-converter","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opensource-nepal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-12T15:22:52.000Z","updated_at":"2025-04-08T07:07:32.000Z","dependencies_parsed_at":"2023-09-24T16:56:46.471Z","dependency_job_id":"2c2f1714-1918-417a-ac14-64e31d85d87d","html_url":"https://github.com/opensource-nepal/node-nepali-datetime","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensource-nepal%2Fnode-nepali-datetime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensource-nepal%2Fnode-nepali-datetime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensource-nepal%2Fnode-nepali-datetime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensource-nepal%2Fnode-nepali-datetime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opensource-nepal","download_url":"https://codeload.github.com/opensource-nepal/node-nepali-datetime/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252890447,"owners_count":21820392,"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":["ad-to-bs","bs-to-ad","javascript","nepal","nepali","nepali-date","nepali-date-conversion","nepali-date-converter","typescript"],"created_at":"2025-05-07T13:47:55.328Z","updated_at":"2025-05-07T13:47:55.881Z","avatar_url":"https://github.com/opensource-nepal.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nepali-datetime\n\n[![npm version](https://img.shields.io/npm/v/nepali-datetime?color=48c21a)](https://www.npmjs.com/package/nepali-datetime)\n[![Github CI](https://github.com/opensource-nepal/node-nepali-datetime/actions/workflows/ci.yml/badge.svg)](https://github.com/opensource-nepal/node-nepali-datetime/actions/workflows/ci.yml)\n[![Downloads](https://img.shields.io/npm/dm/nepali-datetime?maxAge=180)](https://www.npmjs.com/package/nepali-datetime)\n[![codecov](https://codecov.io/gh/opensource-nepal/node-nepali-datetime/branch/main/graph/badge.svg?token=KAKOA8A036)](https://codecov.io/gh/opensource-nepal/node-nepali-datetime)\n[![License](https://img.shields.io/npm/l/nepali-datetime?label=License)](https://github.com/opensource-nepal/node-nepali-datetime/blob/main/LICENSE)\n\nnepali-datetime is a Node.js package designed to provide native JavaScript-like features for Nepali dates. It includes the 'NepaliDate' class for Nepali date support and the 'dateConverter' module for date conversion.\n\n## Examples\n\nHere are a few examples to get you started:\n\n```javascript\nimport NepaliDate from 'nepali-datetime'\n\n// Create a NepaliDate object for the current date and time\nconst now = new NepaliDate()\nconsole.log(now.toString()) // 2080-03-23 15:32:03.643\n\n// Create a NepaliDate object from a Nepali date string\nconst date1 = new NepaliDate('2079-02-15 23:11')\nconsole.log(date1.toString()) // 2079-02-15 23:11:00\n\n// Parse Nepali date string\nconst date2 = new NepaliDate('Baisakh 18, 2080', 'MMMM D, YYYY')\nconsole.log(date2.toString()) // 2080-01-18 00:00:00\n\n// Format a NepaliDate object\nconst formattedDate = now.format('YYYY-MM-DD')\nconsole.log(formattedDate) // 2080-03-23\n\n// Create a NepaliDate object from an English date string\nconst date3 = NepaliDate.parseEnglishDate('2023-07-08', 'YYYY-MM-DD')\nconsole.log(date3.toString()) // 2080-03-23 00:00:00\n```\n\n## Installation\n\nTo install nepali-datetime, you can use npm or yarn:\n\n```shell\nnpm install nepali-datetime\n```\n\nor\n\n```shell\nyarn add nepali-datetime\n```\n\n## Usage\n\n### NepaliDate\n\nThe `NepaliDate` class represents a Nepali calendar date. It provides various methods and properties to work with Nepali dates.\n\n#### Creating a NepaliDate object\n\nYou can create a `NepaliDate` object in several ways:\n\n- Without any parameters: Creates a `NepaliDate` object for the current date and time.\n\n    ```javascript\n    import NepaliDate from 'nepali-datetime'\n\n    const now = new NepaliDate()\n    ```\n\n- Using a Nepali date string: Parses the string as a Nepali calendar date.\n\n    ```javascript\n    const date1 = new NepaliDate('2079-02-15')\n    const date2 = new NepaliDate('2079-02-15 14:00')\n    ```\n\n- Using a Unix timestamp (in milliseconds):\n\n    ```javascript\n    const date2 = new NepaliDate(1654210800000)\n    ```\n\n- Using a JavaScript `Date` object: Converts the JavaScript `Date` object to a `NepaliDate` object.\n\n    ```javascript\n    const jsDate = new Date()\n    const date3 = new NepaliDate(jsDate)\n    ```\n\n- Using an existing `NepaliDate` object: Creates a new `NepaliDate` object with the same values.\n\n    ```javascript\n    const date4 = new NepaliDate(date3)\n    ```\n\n- Using Nepali calendar date and time parameters: Specifies the components of a Nepali calendar date.\n\n    ```javascript\n    const date5 = new NepaliDate(year, month, date, hour, minute, second, ms)\n    const date6 = new NepaliDate(2079, 2, 15, 10, 30)\n    ```\n\n#### Getting the Nepali date components\n\nYou can retrieve various components of a `NepaliDate` object using the following methods:\n\n- `getDateObject()`: Retrieves the Javascript Date object equivalent to the NepaliDate.\n- `getTime()`: Retrieves the Unix timestamp (in milliseconds) of the Nepali date.\n- `getYear()`: Retrieves the year of the Nepali date in the Nepali calendar.\n- `getEnglishYear()`: Retrieves the year of the Nepali date in the English calendar.\n- `getMonth()`: Retrieves the month of the Nepali date in the Nepali calendar.\n- `getEnglishMonth()`: Retrieves the month of the Nepali date in the English calendar.\n- `getDate()`: Retrieves the day of the month of the Nepali date in the Nepali calendar.\n- `getEnglishDate()`: Retrieves the day of the month of the Nepali date in the English calendar.\n- `getDay()`: Retrieves the day of the week represented by a numeric value.\n- `getHours()`: Retrieves the hour value of the Nepali date.\n- `getMinutes()`: Retrieves the minute value of the Nepali date.\n- `getSeconds()`: Retrieves the second value of the Nepali date.\n- `getMilliseconds()`: Retrieves the millisecond value of the Nepali date.\n\n#### Setting the Nepali date components\n\nYou can set individual components of a `NepaliDate` object using the following methods:\n\n- `setYear(year)`: Sets the year of the Nepali date.\n- `setMonth(month)`: Sets the month of the Nepali date.\n- `setDate(day)`: Sets the day of the month of the Nepali date.\n- `setHours(hour)`: Sets the hour of the Nepali date.\n- `setMinutes(minute)`: Sets the minute of the Nepali date.\n- `setSeconds(second)`: Sets the second of the Nepali date.\n- `setMilliseconds(ms)`: Sets the millisecond of the Nepali date.\n- `setTime(time)`: Sets the Nepali date and time values using a Unix timestamp.\n\n#### Formatting the Nepali date\n\nYou can format a `NepaliDate` object as a string using the `format()` and `formatNepali()` methods.\nAdditionally, you can convert the corresponding English date to a string using the `formatEnglishDate()` and `formatEnglishDateInNepali()` methods.\n\n- `format(formatStr)`: Returns a string representation (in English) of the `NepaliDate` object in the specified format.\n- `formatNepali(formatStr)`: Returns a string representation in the Nepali (Devanagari script) of the `NepaliDate` object in the specified format.\n- `formatEnglishDate(formatStr)`: Returns a string representation (in English) of the English Date in the specified format.\n- `formatEnglishDateInNepali(formatStr)`: Returns a string representation in the Nepali (Devanagari script) of the English Date in the specified format.\n\n```javascript\nconst date = new NepaliDate(2079, 5, 3, 16, 14)\nconsole.log(date.format('YYYY-MM-DD hh:mm A')) // 2079-06-03 04:14 PM\nconsole.log(date.formatEnglishDate('YYYY-MM-DD hh:mm A')) // 2022-09-19 04:14 PM\n```\n\nThe date formatting will follow the format codes mentioned below, which are similar to the date formats used in day.js.\n\n| Format Token | Description                       | Example  |\n| ------------ | --------------------------------- | -------- |\n| YYYY         | 4-digit year                      | 2023     |\n| YY           | 2-digit year                      | 23       |\n| MMMM         | Full month name                   | Baisakh  |\n| MMM          | Abbreviated month name            | Bai      |\n| MM           | 2-digit month                     | 01-12    |\n| M            | Month number, beginning at 1      | 1-12     |\n| DD           | 2-digit day of the month          | 01-31    |\n| D            | Day of the month                  | 1-31     |\n| dddd         | Full day of the week              | Monday   |\n| ddd          | Abbreviated day of the week       | Mon      |\n| d            | Day of the week, with Sunday as 0 | 0-6      |\n| HH           | 2-digit hour (24-hour format)     | 00-23    |\n| H            | Hour (24-hour format)             | 0-23     |\n| hh           | 2-digit hour (12-hour format)     | 01-12    |\n| h            | Hour (12-hour format)             | 1-12     |\n| mm           | 2-digit minutes                   | 00-59    |\n| m            | Minutes                           | 0-59     |\n| ss           | 2-digit seconds                   | 00-59    |\n| s            | Seconds                           | 0-59     |\n| SSS          | 3-digit milliseconds              | 000-999  |\n| A            | Uppercase AM/PM                   | AM or PM |\n| a            | Lowercase am/pm                   | am or pm |\n\nAny other character will be printed as it is. If you need to print the special characters (YMDmd), please enclose them within square brackets. Example: `.format(\"[YMDmd]\")`\n\nFor the list of month names and their abbreviations, you can refer to the table below.\n\n| Value of Month | Abbreviation | Full Name |\n| -------------- | ------------ | --------- |\n| 0              | Bai          | Baisakh   |\n| 1              | Jes          | Jestha    |\n| 2              | Asa          | Asar      |\n| 3              | Shr          | Shrawan   |\n| 4              | Bhd          | Bhadra    |\n| 5              | Asw          | Aswin     |\n| 6              | Kar          | Kartik    |\n| 7              | Man          | Mangsir   |\n| 8              | Pou          | Poush     |\n| 9              | Mag          | Magh      |\n| 10             | Fal          | Falgun    |\n| 11             | Cha          | Chaitra   |\n\n#### Converting to JavaScript Date object\n\nYou can get the equivalent JavaScript `Date` object of a `NepaliDate` object using the `getDateObject()` method.\n\n```javascript\nconst now = new NepaliDate(2079, 5, 3)\nconsole.log(now.getDateObject()) // Date 2022-09-18T18:15:00.000Z\n```\n\n#### Creating a NepaliDate object from an English date\n\nYou can create a `NepaliDate` object from an English calendar date using the `parseEnglishDate` or `fromEnglishDate` method.\n\n```javascript\nconst date1 = NepaliDate.parseEnglishDate('2023-07-08', 'YYYY-MM-DD')\nconsole.log(date1.toString()) // 2080-03-23 00:00:00\n\nconst date2 = NepaliDate.fromEnglishDate(2023, 6, 8, 10, 15)\nconsole.log(date2.toString()) // 2080-03-23 10:15:00\n```\n\n#### Others\n\n- `NepaliDate.getDaysOfMonth(year, month)`: Returns the number of days in a specific month of a given year.\n- `NepaliDate.minSupportedDate()`: Returns the minimum supported JS Date object.\n- `NepaliDate.maxSupportedDate()`: Returns the maximum supported JS Date object.\n- `NepaliDate.minSupportedNepaliDate()`: Returns the minimum supported Nepali object.\n- `NepaliDate.maxSupportedNepaliDate()`: Returns the maximum supported Nepali object.\n\n### dateConverter\n\nThe `dateConverter` module provides core functions for converting dates between the Nepali and English calendars.\n\n- `englishToNepali(year, month, day)`: Converts an English calendar date to a Nepali calendar date. Returns an array `[npYear, npMonth, npDay]` representing the Nepali date.\n- `nepaliToEnglish(year, month, day)`: Converts a Nepali calendar date to an English calendar date. Returns an array `[enYear, enYear, enDay]` representing the English date.\n\n\u003e Note: Use 0 as the value for the months Baisakh and January (Javascript Logic 🤷).\n\n```javascript\nimport dateConverter from 'nepali-datetime/dateConverter'\n\n// english to nepali date conversion\nconst [npYear, npMonth, npDay] = dateConverter.englishToNepali(2023, 5, 27)\n\n// nepali to english date conversion\nconst [enYear, enMonth, enDay] = dateConverter.nepaliToEnglish(2080, 2, 15)\n```\n\n#### Quick Date conversion using NepaliDate\n\nThe `NepaliDate` class can also be used for direct string-to-string date conversions, eliminating the need for custom parsing or formatting logic.\n\n**English Date to Nepali Date**\n\n```javascript\nconst enDate = '2024-11-25'\nconst npDate = NepaliDate.parseEnglishDate(enDate, 'YYYY-MM-DD').format('YYYY-MM-DD')\n// 2081-08-10\n```\n\n**Nepali Date to English Date**\n\n```javascript\nconst npDate = '2081-08-10'\nconst enDate = new NepaliDate(npDate).formatEnglishDate('YYYY-MM-DD')\n// 2024-11-25\n```\n\n## Acknowledgements\n\nThis project was inspired by [nepali-date](https://github.com/sharingapples/nepali-date). We would like to express our gratitude to their team for their excellent work and ideas, which served as a motivation for this project.\n\n## Contribution\n\nWe appreciate feedback and contribution to this package. To get started please see our [contribution guide](CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensource-nepal%2Fnode-nepali-datetime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopensource-nepal%2Fnode-nepali-datetime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensource-nepal%2Fnode-nepali-datetime/lists"}