Template talk:Age in years

From Team Fortress Wiki
Jump to: navigation, search

Help Meee!

I'm fairly new to programming so a little help here would be appreciated. I have a couple of problems with this template:

  1. Firstly, I don't think my calculations are right - the wrong year will be produced if you are less than half-way to your next Birthday. This is because I had to use the round command to keep the years as whole numbers (i.e. your age would appear as 20.348). If anyone knows a way of making the program ignore any decimal places that would be a big help.
  2. I'm also having trouble figuring out how to calculate how many days to add on for leap-years. Well, I can't get the if command to work in this case anyway.

Thanks to anyone who can help. I can't even begin to imagine how you people who program the bots and such do this.

» Cooper Kid (blether·contreebs) 15:48, 11 August 2011 (PDT)
I don't know much about coding, but:
  1. Isn't there a way to force it so the numbers are always rounded down?
  2. I really don't know if it's possible to do this.
 –  Duel RED.png Epic Eric Duel BLU.png (T | C) 15:55, 11 August 2011 (PDT)

I'm pretty sure there's a Javascript command called something like roundup which forces all decimals to be rounded up, but getting this to work in Wikitext is the issue. As for my second problem, I've had a think and I'm certain that it can be done - any year divisible by 4 is a leap-year, so all that needs to be done is to add a day for each leap-year between the start date and the present date. Or something. » Cooper Kid (blether·contreebs) 16:44, 11 August 2011 (PDT)

You're forgetting about years that end in -00 and aren't multiples of 400.  –  Duel RED.png Epic Eric Duel BLU.png (T | C) 17:22, 14 August 2011 (PDT)
I said divisible by 4, not 400 =P Also I doubt anyone wanting to use this will need to set any date before the 50s at the earliest.

I'm thinking a loop counting from start year to present year will count the total years, divide each by 4 as it is counted to find out if it is a leap year, then add a day to the final result for each leap year. That should do it. » Cooper Kid (blether·contreebs) 17:48, 14 August 2011 (PDT)

Why reinvent the wheel?

See w:Template:Age. There's no reason that template wouldn't work here. coreycubed / talk 12:05, 15 August 2011 (PDT)

Specifically, {{#expr:({{{4|{{CURRENTYEAR}}}}})-({{{1}}})-(({{{5|{{CURRENTMONTH}}}}})<({{{2}}})or({{{5|{{CURRENTMONTH}}}}})=({{{2}}})and({{{6|{{CURRENTDAY}}}}})<({{{3}}}))}}. coreycubed / talk 12:09, 15 August 2011 (PDT)
Why indeed? Because I'm an idiot. Perhaps I've been a little bit too exuberant with the Boston Basher. I've finished the template now anyway, but thanks for pointing this out - I'll remember to check the Wiki templates for stuff like this in the future. » Cooper Kid (blether·contreebs) 12:12, 15 August 2011 (PDT)
Okay, sorry if I stepped on your toes a bit... I went through and updated the template and the docs, but it seems like you had it well under control! I saw the edit summary and it seemed like you were unsure. Anyways, feel free to revert it back if you like your code better. :) coreycubed / talk 12:14, 15 August 2011 (PDT)
Not at all, yours is much simpler! What a coincidence we both tried to fix it at the same time, eh =) Thanks for sorting it out! » Cooper Kid (blether·contreebs) 12:16, 15 August 2011 (PDT)