Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jalaaliToTimestamp function #31

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ Convert Jalaali calendar date to javascript Date object by giving Jalaali year,
```js
jalaali.jalaaliToDateObject(1400, 4, 30) // new Date(2021, 6, 21)
```
### jalaaliToTimestamp(jy, jm, jd, millisecond = true)

Convert Jalaali calendar date to Timestamp.

```js
jalaali.jalaaliToTimestamp(1400, 4, 30) // 1626809400000
```

## License

Expand Down
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports =
, g2d: g2d
, d2g: d2g
, jalaaliToDateObject: jalaaliToDateObject
, jalaaliToTimestamp: jalaaliToTimestamp
}

/*
Expand Down Expand Up @@ -314,4 +315,16 @@ function mod(a, b) {
gregorianCalenderDate.gm - 1,
gregorianCalenderDate.gd
);
}

/**
* Convert Jalaali calendar dates to Timestamp
* @param {number} jy jalaali year
* @param {number} jm jalaali month
* @param {number} jd jalaali day
* @param {boolean} [millisecond=true] calculate millisecond
* @returns Timestamp
*/
function jalaaliToTimestamp(jy, jm, jd, millisecond = true) {
return jalaaliToDateObject(jy, jm, jd).getTime() / (millisecond ? 1 : 1000);
}