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

methods return array #43

Closed
wants to merge 4 commits 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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,23 @@ Or use a CDN:
Converts a Gregorian date to Jalaali.

```js
jalaali.toJalaali(2016, 4, 11) // { jy: 1395, jm: 1, jd: 23 }
jalaali.toJalaali(2016, 4, 11) // [1395, 1, 23 ]
```

### toJalaali(date)

Converts a JavaScript Date object to Jalaali.

```js
jalaali.toJalaali(new Date(2016, 3, 11)) // { jy: 1395, jm: 1, jd: 23 }
jalaali.toJalaali(new Date(2016, 3, 11)) // [1395, 1, 23 ]
```

### toGregorian(jy, jm, jd)

Converts a Jalaali date to Gregorian.

```js
jalaali.toGregorian(1395, 1, 23) // { gy: 2016, gm: 4, gd: 11 }
jalaali.toGregorian(1395, 1, 23) // [2016, 4, 11 ]
```

### isValidJalaaliDate(jy, jm, jd)
Expand Down Expand Up @@ -165,7 +165,7 @@ jalaali.j2d(1395, 1, 23) // 2457490
Converts the Julian Day number to a date in the Jalaali calendar.

```js
jalaali.d2j(2457490) // { jy: 1395, jm: 1, jd: 23 }
jalaali.d2j(2457490) // [1395, 1, 23 ]
```

### g2d(gy, gm, gd)
Expand All @@ -181,7 +181,7 @@ jalaali.g2d(2016, 4, 11) // 2457490
Calculates Gregorian and Julian calendar dates from the Julian Day number (jdn) for the period since jdn=-34839655 (i.e. the year -100100 of both calendars) to some millions years ahead of the present.

```js
jalaali.d2g(2457490) // { gy: 2016, gm: 4, gd: 11 }
jalaali.d2g(2457490) // [2016, 4, 11 ]
```

### jalaaliToDateObject(jy, jm, jd)
Expand All @@ -197,7 +197,7 @@ jalaali.jalaaliToDateObject(1400, 4, 30) // new Date(2021, 6, 21)
Return Saturday and Friday day of current week(week start in Saturday)

```js
jalaali.jalaaliWeek(1400, 4, 30) // { saturday: { jy: 1400, jm: 4, jd: 26 }, friday: { jy: 1400, jm: 5, jd: 1 } }
jalaali.jalaaliWeek(1400, 4, 30) // { saturday: [1400, 4, 26 ], friday: [1400, 5, 1 ] }
```

## License
Expand Down
24 changes: 6 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function jalaaliMonthLength(jy, jm) {
/*
This function determines if the Jalaali (Persian) year is
leap (366-day long) or is the common year (365 days)

@param jy Jalaali calendar year (-61 to 3177)
@returns number of years since the last leap year (0 to 4)
*/
Expand Down Expand Up @@ -111,7 +110,6 @@ function jalCalLeap(jy) {
leap (366-day long) or is the common year (365 days), and
finds the day in March (Gregorian calendar) of the first
day of the Jalaali year (jy).

@param jy Jalaali calendar year (-61 to 3177)
@param withoutLeap when don't need leap (true or false) default is false
@return
Expand Down Expand Up @@ -180,7 +178,6 @@ function jalCal(jy, withoutLeap) {

/*
Converts a date of the Jalaali calendar to the Julian Day number.

@param jy Jalaali year (1 to 3100)
@param jm Jalaali month (1 to 12)
@param jd Jalaali day (1 to 29/31)
Expand All @@ -193,15 +190,14 @@ function j2d(jy, jm, jd) {

/*
Converts the Julian Day number to a date in the Jalaali calendar.

@param jdn Julian Day number
@return
jy: Jalaali year (1 to 3100)
jm: Jalaali month (1 to 12)
jd: Jalaali day (1 to 29/31)
*/
function d2j(jdn) {
var gy = d2g(jdn).gy // Calculate Gregorian year (gy).
var gy = d2g(jdn)[0] // Calculate Gregorian year (gy).
, jy = gy - 621
, r = jalCal(jy, false)
, jdn1f = g2d(gy, 3, r.march)
Expand Down Expand Up @@ -233,10 +229,7 @@ function d2j(jdn) {
}
jm = 7 + div(k, 30)
jd = mod(k, 30) + 1
return { jy: jy
, jm: jm
, jd: jd
}
return [jy, jm, jd]
}

/*
Expand All @@ -245,7 +238,6 @@ function d2j(jdn) {
the date (i.e. 12 hours of Universal Time).
The procedure was tested to be good since 1 March, -100100 (of both
calendars) up to a few million years into the future.

@param gy Calendar year (years BC numbered 0, -1, -2, ...)
@param gm Calendar month (1 to 12)
@param gd Calendar day of the month (1 to 28/29/30/31)
Expand All @@ -263,7 +255,6 @@ function g2d(gy, gm, gd) {
Calculates Gregorian and Julian calendar dates from the Julian Day number
(jdn) for the period since jdn=-34839655 (i.e. the year -100100 of both
calendars) to some millions years ahead of the present.

@param jdn Julian Day number
@return
gy: Calendar year (years BC numbered 0, -1, -2, ...)
Expand All @@ -282,10 +273,7 @@ function d2g(jdn) {
gd = div(mod(i, 153), 5) + 1
gm = mod(div(i, 153), 12) + 1
gy = div(j, 1461) - 100100 + div(8 - gm, 6)
return { gy: gy
, gm: gm
, gd: gd
}
return [gy, gm ,gd]
}

/**
Expand Down Expand Up @@ -330,9 +318,9 @@ function jalaaliToDateObject(
var gregorianCalenderDate = toGregorian(jy, jm, jd);

return new Date(
gregorianCalenderDate.gy,
gregorianCalenderDate.gm - 1,
gregorianCalenderDate.gd,
gregorianCalenderDate[0],
gregorianCalenderDate[1] - 1,
gregorianCalenderDate[2],
h || 0,
m || 0,
s || 0,
Expand Down