View Single Post
Old 11-17-2012, 10:44 PM   PM User | #17
Durakken
New to the CF scene

 
Join Date: Nov 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Durakken is an unknown quantity at this point
Grrr... so I got the next one all programmed out... and now I'm stuck yet again...
Whenever a multiple of 2557 is entered the date returned is wrong and this seems to push the date off a little.

Here's the code. I'm pretty sure it has something to do with the fix I tried with nDays%2557

edit: ^.^ I figured out what the problem was sort of, (and edited it into the code) but I also forgot something... which kinda throws a wrench into this whole thing like the leap year thing did... This system is supposed to have a reverse leap year which is why 10227 is supposed to align with the Julian Calender. The reverse leap is supposed to be that last day off the 4th Cycle. Is there any way to fudge this so that that happens and is still accurate or is do I have to refigure this out?

edit2: never mind...fixed ^.^ I just used day subtraction after i realized that if i subtract 10227 from 10228 it'll restart with 1 so i just needed a way to keep track of the cycles after that. yar
Code:
<html>
<body>
<form id="theForm" onsubmit="return false;">
Number of days: <input id="days" name="days" onchange="getDate();" />
<br/>
<input type="button" value="Calculate" onclick="getDate();" />
</form>
<hr/>
Dr date: <span id="jDate"></span>

<script type="text/javascript">
function getDate()
{
    getJulianDate()
}

function getJulianDate( )
{
    var nDays = Number( document.getElementById("days").value );

    var Cycle = Math.floor(nDays / 2557);
    if(nDays%2557 != 0) 
    {
        nDays -= Cycle*2557;
        Cycle++;
    } else {
        nDays = 2557;
    }

    var years = [343,343,343,343,343,343,343,147,9];
    theYear = 0;
    for ( var y = 0; y < 9; ++y)
    {
        if ( nDays <= years[y] )
        {
            theYear = y +1;
            break;
        }
        nDays -= years[y]
    }

    var mnames = ["Darusitar","Bendratar","Enzer","Mizutar","Genutar","Krinzitar",
              "Niemetar"];
    var mDays = [ 49,21 ];
    var s = 0;
    if (theYear >= 8) { s = 1; }

    var theMonth = -1;
    for ( var m = 0; m < 7; ++m )
    {
        if ( nDays <= mDays[s] )
        {
            theMonth = m;
            break; // out of for loop
        }
        nDays -= mDays[s];
    }

    if ( theYear == 9)
    {
        var monthName = "Morgetar";
    } else {
        var monthName = mnames[theMonth];
    }
    
    document.getElementById("jDate").innerHTML = 
        monthName+ " " +nDays+ ", " +theYear+"."+Cycle+ "T";
}
</script>
</body>
</html>

Last edited by Durakken; 11-18-2012 at 01:31 AM..
Durakken is offline   Reply With Quote