{"id":18021209,"url":"https://github.com/yousefvand/persian-date-parser","last_synced_at":"2025-03-26T22:30:37.812Z","repository":{"id":57322286,"uuid":"290755894","full_name":"yousefvand/persian-date-parser","owner":"yousefvand","description":"Parser library for date and time. Supports Jalali, Gregorian or mixed.","archived":false,"fork":false,"pushed_at":"2020-10-27T10:12:22.000Z","size":712,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-06T22:46:18.414Z","etag":null,"topics":["calendar","datetime","gregorian","jalali","nodejs","parser","parsing","persian"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/yousefvand.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}},"created_at":"2020-08-27T11:20:28.000Z","updated_at":"2023-10-18T11:37:48.000Z","dependencies_parsed_at":"2022-08-26T01:11:20.763Z","dependency_job_id":null,"html_url":"https://github.com/yousefvand/persian-date-parser","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousefvand%2Fpersian-date-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousefvand%2Fpersian-date-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousefvand%2Fpersian-date-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousefvand%2Fpersian-date-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yousefvand","download_url":"https://codeload.github.com/yousefvand/persian-date-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245747405,"owners_count":20665783,"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":["calendar","datetime","gregorian","jalali","nodejs","parser","parsing","persian"],"created_at":"2024-10-30T06:09:07.793Z","updated_at":"2025-03-26T22:30:37.535Z","avatar_url":"https://github.com/yousefvand.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Persian date parser\n\n[![npm version](https://badge.fury.io/js/persian-date-parser.svg)](https://badge.fury.io/js/persian-date-parser) [![GitHub forks](https://img.shields.io/github/forks/yousefvand/persian-date-parser)](https://github.com/yousefvand/persian-date-parser/network) [![GitHub stars](https://img.shields.io/github/stars/yousefvand/persian-date-parser)](https://github.com/yousefvand/persian-date-parser/stargazers) [![GitHub issues](https://img.shields.io/github/issues/yousefvand/persian-date-parser)](https://github.com/yousefvand/persian-date-parser/issues) [![Code coverage](https://img.shields.io/badge/coverage-100%25-blueviolet)](https://github.com/yousefvand/persian-date-parser) [![GitHub license](https://img.shields.io/github/license/yousefvand/persian-date-parser)](https://github.com/yousefvand/persian-date-parser/blob/master/LICENSE)\n\nLibrary for parsing date and time to desired format (Jalali, Gregorian or mixed).\n\nWhen possible consider using built-in [Date.prototype.toLocaleDateString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString#:~:text=The%20toLocaleDateString()%20method%20returns,the%20behavior%20of%20the%20function.) method.\n\n## Usage\n\n```bash\n\u003e npm i persian-date-parser\n```\n\n```js\nconst parser = require('persian-date-parser')\n```\n\nFrom the above line `parser` accepts two optional arguments: `cache capacity` and `cache type`. Each cache entry has a string (format) as its key (i.e. `'gyyyy-gm-gd'`) and a function as its value. If in your use-case format strings are limited, parser can benefit from caching those functions. On subsequent parsings for the same format, tokenizing and arranging steps are the same and can be bypassed by using cache, which results in better performance.\n\n| Cache Capacity | Description                                                            |\n|:--------------:|:-----------------------------------------------------------------------|\n| \u003e 0            | Any positive number. Bigger numbers mean more memory usage.            |\n| 0              | Unlimited caching a.k.a memory leak. Use with caution.                 |\n| \u003c 0            | No caching. Default behavior.                                          |\n\n| Cache Type | Eviction Policy                                                            |\n|:----------:|:-------------------------------|\n| 'FIFO'     | First in first out (default).  |\n| 'LRU'      | Least Recently Used.           |\n\n```js\nconst parse = parser() // no caching by default\n```\n\nor\n\n```js\nconst parse = parser(1000) // or parser(1000, 'LRU')\n```\n\n```js\nconst now = new Date()\n```\n\nJalali example:\n\n```js\nconst format = 'pjyyyy/pjmm/pjdd - pjdddd - pjHH:pjMM pjTT'\nconst result = parse(format, now)\n// result: ۱۳۹۹/۰۶/۰۹ - یکشنبه - ۲۱:۳۶ ب.ظ\n```\n\nGregorian Example:\n\n```js\nconst format = 'gyyyy/gmm/gdd - gdddd - gHH:gMM gTT'\nconst result = parse(format, now)\n// result: 2020/08/30 - Sunday - 21:36 PM\n```\n\n## Masks\n\nMasks are according to following table but there are three general prefixes used with them. Using `g` or `j` is mandatory.\n\n- `g`: **Gregorian** date.\n\n- `j`: **Jalali** date.\n\n- `p`: Represent results in **Persian** (numbers, month names, weekdays and their abbreviations).\n\n| Mask | Description                                                            |\n|:-----|:-----------------------------------------------------------------------|\n| d    | Day of the month as digits. No leading zero for single-digit days.     |\n| dd   | Day of the month as digits. Leading zero for single-digit days.        |\n| ddd  | Day of the week as a three-letter abbreviation. Persian -\u003e one-letter. |\n| dddd | Day of the week as its full name.                                      |\n| m    | Month as digits. No leading zero for single-digit months.              |\n| mm   | Month as digits. Leading zero for single-digit months.                 |\n| mmm  | Month as a three-letter abbreviation.                                  |\n| mmmm | Month as its full name.                                                |\n| yy   | Year as last two digits. Leading zero for years less than 10.          |\n| yyyy | Year represented by four digits.                                       |\n| h    | Hours. No leading zero for single-digit hours (12-hour clock).         |\n| hh   | Hours. Leading zero for single-digit hours (12-hour clock).            |\n| H    | Hours. No leading zero for single-digit hours (24-hour clock).         |\n| HH   | Hours. Leading zero for single-digit hours (24-hour clock).            |\n| M    | Minutes. No leading zero for single-digit minutes.                     |\n| MM   | Minutes. Leading zero for single-digit minutes.                        |\n| s    | Seconds. No leading zero for single-digit seconds.                     |\n| ss   | Seconds. Leading zero for single-digit seconds.                        |\n| t    | Lowercase, single-character time marker string: a or p.                |\n| tt   | Lowercase, two-character time marker string: am or pm.                 |\n| T    | Uppercase, single-character time marker string: A or P.                |\n| TT   | Uppercase, two-character time marker string: AM or PM.                 |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyousefvand%2Fpersian-date-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyousefvand%2Fpersian-date-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyousefvand%2Fpersian-date-parser/lists"}