bikram-sambat
Advanced tools
Comparing version 1.0.0 to 1.3.7
{ | ||
"name": "bikram-sambat", | ||
"version": "1.0.0", | ||
"description": "JS utilities for converting between the Nepali Bikram Sambat (Vikram Samvat) and Gregorian (standard European) calendars.", | ||
@@ -37,3 +36,4 @@ "main": "src/index.js", | ||
"eurodigit": "^2.1.1" | ||
} | ||
} | ||
}, | ||
"version": "1.3.7" | ||
} |
var toDevanagari = require('eurodigit/src/to_devanagari'); | ||
var MS_PER_DAY = 86400000; | ||
// We have defined our own Epoch for Bikram Sambat: 1-1-2007 BS / 13-4-1950 AD | ||
var BS_EPOCH_TS = -622359900000; // = Date.parse('1950-4-13') | ||
var BS_YEAR_ZERO = 2007; | ||
// TODO this would be stored more efficiently converted to a string using | ||
@@ -25,11 +31,6 @@ // String.fromCharCode.apply(String, ENCODED_MONTH_LENGTHS), and extracted using | ||
/** | ||
* Magic numbers: | ||
* 86400000 <- the number of miliseconds in a day | ||
* 2007 <- The year (BS) whose first day is our Bikram Sambat Epoch (BSE) | ||
* -622359900000 <- Date.parse('1950-4-13') = unix timestamp of BSE | ||
*/ | ||
function toBik(greg) { | ||
var m, dM, year = 2007, | ||
days = Math.floor((Date.parse(greg) + 622359900000) / 86400000) + 1; | ||
// TODO do not use Date.parse(), as per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse | ||
var m, dM, year = BS_YEAR_ZERO, | ||
days = Math.floor((Date.parse(greg) - BS_EPOCH_TS) / MS_PER_DAY) + 1; | ||
@@ -62,2 +63,26 @@ while(days > 0) { | ||
function toGreg(year, month, day) { | ||
var timestamp = BS_EPOCH_TS; | ||
while(year >= BS_YEAR_ZERO) { | ||
while(month >= 1) { | ||
while(day >= 1) { | ||
timestamp += MS_PER_DAY; | ||
--day; | ||
} | ||
--month; | ||
day = daysInMonth(year, month, day); | ||
} | ||
--year; | ||
month = 12; | ||
day = daysInMonth(year, month, day); | ||
} | ||
var d = new Date(timestamp); | ||
return { | ||
year: d.getUTCFullYear(), | ||
month: 1+d.getUTCMonth(), | ||
day: d.getUTCDate() | ||
}; | ||
} | ||
module.exports = { | ||
@@ -67,3 +92,4 @@ daysInMonth: daysInMonth, | ||
toBik_euro: toBik_euro, | ||
toBik_text: toBik_text | ||
toBik_text: toBik_text, | ||
toGreg: toGreg | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
7512
5
187
2
0
1
1