first pass of the greg to unity conversion
This commit is contained in:
parent
e4917f8cea
commit
0188404198
@ -17,7 +17,11 @@ const monthdays = 30
|
||||
const leapfreq = 8
|
||||
|
||||
const exleapcyclelength = 800;
|
||||
const extraleapyear = 500;
|
||||
const exleapyear = 500;
|
||||
const exleapyearlowbound = Math.floor(exleapyear / leapfreq) * leapfreq;
|
||||
const exleapyearupbound = exleapyearlowbound + leapfreq;
|
||||
const exleapyearlowbounddays = (exleapyearlowbound * yeardays) + ((exleapyearlowbound / leapfreq) * leapchange);
|
||||
const exleapyearupbounddays = (exleapyearupbound * yeardays) + leapchange + ((exleapyearupbound / leapfreq) * leapchange);
|
||||
|
||||
const exleapcycledays = (exleapcyclelength * yeardays) + leapchange + ((exleapcyclelength / leapfreq) * leapchange)
|
||||
|
||||
@ -33,27 +37,49 @@ function unixtounity(unixtime) {
|
||||
|
||||
const exleapcycleprogress = days - exleapcycles * exleapcycledays;
|
||||
|
||||
const leapcycles = Math.floor(exleapcycleprogress / leapcycledays);
|
||||
let leapcycles;
|
||||
|
||||
const leapcycleprogress = exleapcycleprogress - leapcycles * leapcycledays;
|
||||
let leapcycleprogress;
|
||||
|
||||
let years;
|
||||
let leapcyclehasex;
|
||||
|
||||
let yearprogress;
|
||||
if (exleapcycleprogress < exleapyearupbounddays) {
|
||||
|
||||
if (leapcycleprogress > leapyeardays) {
|
||||
leapcycles = Math.floor(exleapcycleprogress / leapcycledays);
|
||||
|
||||
years = Math.floor((leapcycleprogress - leapyeardays) / yeardays) + 1;
|
||||
leapcycleprogress = exleapcycleprogress - leapcycles * leapcycledays;
|
||||
|
||||
yearprogress = leapcycleprogress - ((years * yeardays) + leapchange);
|
||||
leapcyclehasex = exleapcycleprogress >= exleapyearlowbounddays;
|
||||
|
||||
} else {
|
||||
|
||||
years = 0;
|
||||
leapcycles = Math.floor((exleapcycleprogress - leapchange)/ leapcycledays);
|
||||
|
||||
yearprogress = leapcycleprogress;
|
||||
leapcycleprogress = (exleapcycleprogress - (leapcycles * leapcycledays)) - leapchange;
|
||||
|
||||
leapcyclehasex = false;
|
||||
|
||||
}
|
||||
|
||||
let leapyearspassed;
|
||||
|
||||
if (leapcycleprogress < leapyeardays) {
|
||||
|
||||
leapyearspassed = 0;
|
||||
|
||||
} else if (!leapcyclehasex || leapcycleprogress < (2 * leapyeardays) + (3 * yeardays)) {
|
||||
|
||||
leapyearspassed = 1;
|
||||
|
||||
} else {
|
||||
|
||||
leapyearspassed = 2;
|
||||
|
||||
}
|
||||
|
||||
const years = Math.floor((leapcycleprogress - (leapchange * leapyearspassed)) / yeardays);
|
||||
|
||||
const yearprogress = leapcycleprogress - ((years * yeardays) + (leapchange * leapyearspassed));
|
||||
|
||||
const months = Math.floor(yearprogress / monthdays);
|
||||
|
||||
@ -69,6 +95,11 @@ const oldtimes = new Date();
|
||||
oldtimes.setYear(-600)
|
||||
|
||||
console.log(unixtounity(Date.now()))
|
||||
console.log(unixtounity(Date.parse("3500-03-03")))
|
||||
console.log(unixtounity(Date.parse("0010-12-30")))
|
||||
console.log(unixtounity(oldtimes.getTime()))
|
||||
console.log(unixtounity(oldtimes.getTime()))
|
||||
console.log(unixtounity(Date.parse("2000-01-01")))
|
||||
console.log(unixtounity(Date.parse("2000-03-07")))
|
||||
console.log(unixtounity(Date.parse("2000-03-08")))
|
||||
console.log(unixtounity(Date.parse("2000-03-09")))
|
||||
console.log(unixtounity(Date.parse("2001-03-07")))
|
||||
console.log(unixtounity(Date.parse("3000-03-07")))
|
||||
console.log(unixtounity(Date.parse("42400-03-07")))
|
||||
Loading…
Reference in New Issue
Block a user