forked from alxndrsn/bikram-sambat.js
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This means we can convert a wider range of dates. #8
- Loading branch information
1 parent
18cd8a2
commit 77c090a
Showing
9 changed files
with
165 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://[email protected]/alxndrsn/bikram-sambat.js.git" | ||
"url": "git+ssh://[email protected]/medic/bikram-sambat.git" | ||
}, | ||
"keywords": [ | ||
"bikram", | ||
|
@@ -22,9 +22,9 @@ | |
"author": "alxndrsn", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/alxndrsn/bikram-sambat.js/issues" | ||
"url": "https://github.com/medic/bikram-sambat/issues" | ||
}, | ||
"homepage": "https://github.com/alxndrsn/bikram-sambat.js#readme", | ||
"homepage": "https://github.com/medic/bikram-sambat#readme", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"grunt": "^1.0.1", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const daysInMonth = require('../test-data/daysInMonth.json'); | ||
|
||
/* | ||
INSTRUCTIONS: | ||
1) Update `/test-data/daysInMonth.json` as required | ||
2) The first entry in `/test-data/daysInMonth.json` as the BS Epoch. Take this | ||
and convert it to AD and update the bsEpoch constant below. | ||
3) Run the script: node ./encode-days-in-month.js | ||
4) Copy the output code into the files overwriting the existing hardcoded values | ||
*/ | ||
|
||
// const bsEpoch = false; // eg: '1913-4-13'; | ||
const bsEpoch = '1913-4-13'; | ||
|
||
if (!bsEpoch) { | ||
console.error('Read the instructions at the top of this file before executing.'); | ||
process.exit(1); | ||
} | ||
|
||
const processMonth = decimal => { | ||
const delta = decimal - 29; | ||
const binary = delta.toString(2); | ||
const padded = binary.length === 1 ? '0' + binary : binary; | ||
return padded; | ||
}; | ||
|
||
const processYear = months => { | ||
const binary = months.map(processMonth); | ||
const combined = binary.reverse().join(''); | ||
const decimal = parseInt(combined, 2); | ||
return decimal; | ||
}; | ||
|
||
const encodedLengths = Object.values(daysInMonth).map(processYear); | ||
const yearZero = Object.keys(daysInMonth)[0]; | ||
const bsEpochTs = Date.parse(bsEpoch); | ||
|
||
console.log(` | ||
// JavaScript - copy into js/src/index.js | ||
// ------ TO UPDATE THESE HARDCODED VALUES USE /scripts/encode-days-in-month.js | ||
// We have defined our own Epoch for Bikram Sambat: ${yearZero}-1-1 BS or ${bsEpoch} AD | ||
var BS_EPOCH_TS = ${bsEpochTs}; // = Date.parse('${bsEpoch}') | ||
var BS_YEAR_ZERO = ${yearZero}; | ||
var ENCODED_MONTH_LENGTHS = [ | ||
${encodedLengths.join(',')} | ||
]; | ||
`); | ||
|
||
console.log(` | ||
// Java - copy into java/lib/src/main/java/bikramsambat/BsCalendar.java | ||
// ------ TO UPDATE THESE HARDCODED VALUES USE /scripts/encode-days-in-month.js | ||
// We have defined our own Epoch for Bikram Sambat: ${yearZero}-1-1 BS or ${bsEpoch} AD | ||
private static final long BS_EPOCH_TS = ${bsEpochTs}L; // ${bsEpoch} AD | ||
private static final int BS_YEAR_ZERO = ${yearZero}; | ||
private static final long[] ENCODED_MONTH_LENGTHS = { | ||
${encodedLengths.map(length => length + 'L').join(',')} | ||
}; | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
[ | ||
{ | ||
"bs": [ | ||
1970, | ||
1, | ||
1 | ||
], | ||
"expectedGreg": [ | ||
1913, | ||
4, | ||
13 | ||
] | ||
}, | ||
{ | ||
"bs": [ | ||
2007, | ||
|