Skip to content

Commit

Permalink
chore: refactor hijri calendar script
Browse files Browse the repository at this point in the history
script package.json changes
  • Loading branch information
commenthol committed Dec 28, 2021
1 parent ca00b2d commit 247c1fe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
10 changes: 6 additions & 4 deletions scripts/hebrew-calendar/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"name": "hebrew-calender",
"version": "1.0.0",
"private": true,
"description": "",
"license": "ISC",
"author": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"beautify": "js-beautify -s 2 -o ../../src/internal/hebrew-calendar.js ../../src/internal/hebrew-calendar.js",
"lint": "eslint --fix --ext js .",
"start": "node index.js",
"beautify": "js-beautify -s 2 -o ../../src/internal/hebrew-calendar.js ../../src/internal/hebrew-calendar.js"
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"hebcal": "^2.3.2"
}
Expand Down
22 changes: 13 additions & 9 deletions scripts/hijri-calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,33 @@ const moment = require('moment-hijri')
const filename = path.resolve(__dirname, '../../src/internal/hijri-calendar.js')
const out = {}

const YEAR0 = 580

// only years 1936 ... 2080 are supported by moment-hijri
for (let y = 1969; y <= 2080; y++) {
const iy = y - 580
const iy = y - YEAR0

if (!out.year) {
out.year = iy
}
const iyy = iy - out.year

for (let im = 1; im <= 12; im++) {
const m = moment(iy + '/' + im + '/1', 'iYYYY/iM/iD')
const g = moment(iy + '/' + im + '/1', 'iYYYY/iM/iD')

const my = m.year()
const mm = m.iMonth()
const gy = g.year()
const gm = g.iMonth()

if (!out[my]) {
out[my] = []
if (!out[gy]) {
out[gy] = []
}

if (out[my][mm]) {
out[my][mm] = out[my][mm].concat([m.month(), m.date(), iyy])
const monthDateDiffYear = [g.month(), g.date(), iyy]

if (out[gy][gm]) {
out[gy][gm] = out[gy][gm].concat(monthDateDiffYear)
} else {
out[my][mm] = [m.month(), m.date(), iyy]
out[gy][gm] = monthDateDiffYear
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions scripts/hijri-calendar/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"name": "hijri-calendar",
"version": "1.0.0",
"private": true,
"description": "",
"license": "ISC",
"author": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"beautify": "js-beautify -s 2 -o ../../src/internal/hijri-calendar.js ../../src/internal/hijri-calendar.js",
"lint": "eslint --fix --ext js .",
"start": "node index.js",
"beautify": "js-beautify -s 2 -o ../../src/internal/hijri-calendar.js ../../src/internal/hijri-calendar.js"
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"moment-hijri": "^2.1.2"
}
Expand Down

0 comments on commit 247c1fe

Please sign in to comment.