Yeah... I haven't programmed in a while and really don't want to relearn everything just to do this simple thing so could someone please do this for me?
I need a program where I can stick in a number and it gives me a set of 3 dates. 2 of them I can do because i made them up while the third is the julian calender more or less.
So I need to be able to input a number
then I need to do work on that number to get what year day and month it would be if day 1 is "Jan 1, 1" the year is 365.25 days long (which means every 4th year is a leap year, and I need to be able to put in a number of days up to 20,000,000
I know there is probably some easy trick to doing this but I've never been good with those methods and like i said i haven't programmed in a while so could someone write this up? Nothing fancy... it's for personal quick conversion between these dates.
Basically it needs to be a function that accepts a number up to 20,000,000 and returns write a line of "Julian Calender: Month Day, Year NY" printed on the page...
Ummm...you can NOT use document.write after a page has loaded. When you do, you wipe out all content on the page except what you just wrote.
And not to ask a silly question, but WHY do you want something so incredibly inaccurate? Nobody uses a Julian calendar any more. What possible real world use could it have?
And the other problem is that using a calendar as you have asked for could easily result in illegal dates. e.g., you could easily end up with FEBRUARY 29, 1900, just to pick the obvious example.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
document.write doesn't do that... well on different browsers it doesn't... not really important as i can adjust that.
I know the other things. I considered it and decided to go with this style calender just for the overall simplicity for what i am using it for as the corrections made via the gregorian calender for this particular thing i can just shove aside. Also i want 1900 feb 29 on there... for my purposes that is accurate.
edit... oh wait you mean when i hit the button the button goes away. i know. doesn't matter for this. It works fine how i have it in the code i showed.
And not to ask a silly question, but WHY do you want something so incredibly inaccurate? Nobody uses a Julian calendar any more. What possible real world use could it have?
And the other problem is that using a calendar as you have asked for could easily result in illegal dates. e.g., you could easily end up with FEBRUARY 29, 1900, just to pick the obvious example.
Since the op wants to use the Julian calendar then 1900 is a leap year. My understanding is that in the Julian calendar the only criteria for a leap year is that it be divisible by 4.
Since the op wants to use the Julian calendar then 1900 is a leap year. My understanding is that in the Julian calendar the only criteria for a leap year is that it be divisible by 4.
Yes. The Julian system is "more or less" 365.25 days system with a whole bunch of odd things that happened to it. The gregorian system is 365.2425 or some where close to that, making only centuries divisible by 4 leap years, removing 3 days out of the overall cycle.
The reason for the change was to get the seasons right. The reason I need this is for personal use to convert dates between 3 systems (or perhaps more if I come up with needing more) Some of the systems care about keeping seasons right and some don't. The calenders are for a conworld and I am going with the conceit that the world has a perfect 365.25 year. That way i can make it simple but still keep it close to reality. It's a nice little compromise.
I'm also having a hard time with one of the other calenders cuz it's weird... each week has 7 days and each of month 7 weeks and there are 7 months. At the end of 7 years there is a year of 7 months of 21 days and then a "non" year of 9 days. This system and the Julian system lines up every 28 years having the same number of days. I thought that that would make it easier to calculate longer scale numbers but, meh, i still don't like doing it.
Trouble is, JavaScript will *NOT* display Feb 29, 1900 or Feb 29, 2100.
If you do
Code:
var theDate = new Date( 1900, 1, 29 ); // 1 is February in JS code
document.write( theDate );
JavaScript *will* display "March 1, 1900" back at you.
So in order to display "Feb 29, 1900" you will have to not use JavaScript's Date() object *AT ALL* and essentially re-create the entire calendar system.
Of course it can be done. It's just a real pain in the patootie and you are asking a lot to have somebody write that all for you.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Trouble is, JavaScript will *NOT* display Feb 29, 1900 or Feb 29, 2100.
If you do
Code:
var theDate = new Date( 1900, 1, 29 ); // 1 is February in JS code
document.write( theDate );
JavaScript *will* display "March 1, 1900" back at you.
So in order to display "Feb 29, 1900" you will have to not use JavaScript's Date() object *AT ALL* and essentially re-create the entire calendar system.
Of course it can be done. It's just a real pain in the patootie and you are asking a lot to have somebody write that all for you.
Code looks basically right, but I don't see any need for a switch if done right.
Instead, just have an array of month names and index into the array by the month number.
I only see if-else or switch as a viable way of doing it less there is something. The if-else/switch is needed to select the month in general. There is no other place that that month selection takes place and I also have to remove excess days so it fits to the month.
I don't see another way to do this. I'll use an array for month names, but i don't see how that helps selecting months
Quote:
Originally Posted by Old Pedant
This isn't close to right:
Code:
DayOfYear = days - (year*365)
That ignores any leap years that have already occurred!
year/4 can give the number of leap years, but I don't know where to add it
var mDays = [ 31,28,31,30,31,30,31,31,20,31,30,31 ];
// handle leap year:
mDays[1] = isLeapYear ? 29 : 28;
var theMonth = -1;
for ( var m = 0; m < 12; ++m )
{
if ( days <= mDays[m] )
{
theMonth = m;
break; // out of for loop
}
days -= mdays{m];
}
var monthName = names[theMonth];
But there is a problem with that, as you will discover.
Logically, day ZERO of each year should be Jan 1st.
Probably you can handle that by first subtracting off the number of days that correspond to the correct year and then adding back 1 day before entering the above code. Probably. Untested.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
I figured out this part. Thanks for the help... now to work on the next one... which I hope i can figure out
Here's the code i ended up with... I know it's not all that pretty, but it seems to be working
also yes i know it's probably better if i used your way, Old Pedant, to calculate the date, but i already had this way so I just used it. I probably would switch it if it really mattered ^.^
Why would you do that? People like you infuriate me.
I spent the last few days trying to figure this out while I asked for help, but instead got you being arrogant and then when I get it all figured out and working "oh now i'll give you what i could have done days ago." You just wasted both our times by doing that and one has to wonder about the motives behind your actions.
I had looked at the thread earlier in the day and realized I had a typo in the code I showed you. So I fixed it and then checked to make sure it worked.
And then I got to thinking about the problem and realized that the hard part was that, as I had mentioned, you need a zero-based number of days when dividing by years but you want a 1-based number of days for the days in months. That's when I hit on doing
Code:
var quads = Math.floor( (nDays-1) / 1461 ); // 1461 days in 4 years
nDays -= quads * 1461;
It was more a matter of surrendering to my own stubborness than anything else.
Even AFTER I posted I didn't scroll up and see your post with the right answer!
PLEASE...it was just blindness and my own stubbornness at finally understanding the meat of the problem that drove me to write the code.
I have *STILL* not tested your answer. I am assuming it works and you have tested it.
And here I was so happy at myself for coming up with that "quads" trick.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.