11
0
The idea is this: Write a function to print the length of time from now/today's date (at the time the function is called) until a date supplied as an argument.
Assumptions:
- Input date will always be tomorrow or later, in the future.
- Input date will never be more than 10 years in the future.
Rules:
- Output must be in this format: "[z year(s)], [x month(s)], y day(s) until -Input Date-"
- Output time frame (day/month/year) must be pluralized correctly. i.e.
1 month
, not1 months
- Input can be in whichever date format you prefer (3/15/12 - March 15, 2012 - 2012.03.15).
Example: Assuming program is run on March 15, 2012:
- Input date of
3/20/12
=5 days until 3/20/12
- NOT Input date of
4/16/12
=1 month, 1 days until 3/20/12
- Input date of
2012.04.20
=1 month, 5 days until 2012.04.20
- NOT Input date of
2012.04.20
=36 days until 2012.04.20
- Input date of
10/31/17
=5 years, 7 months, 16 days until 10/31/17
- Input date of
3/15/13
=1 year until 3/15/13
This is code golf, so shortest length code wins.
I suppose for the sake of having a deadline, I will be selecting an answer on:
March 23, 2012!
(This is my first CG question, so I'll be happy to correct any question errors on my part!)
3Wolfram|Alpha 10 chars:
now until <input time>
:p – Griffin – 2012-03-15T22:16:57.7203@Griffin 4 chars:
now-<input time>
– PhiNotPi – 2012-03-15T22:23:38.0931@PhiNotPi well played, good sir. – Griffin – 2012-03-15T22:24:41.453
2Is it okay to say "1 days until 3/16/12"? – MrZander – 2012-03-15T23:32:32.283
@MrZander No. I'll update the question. If the number is 1, then there should be no pluralization. – Gaffi – 2012-03-15T23:53:05.257
Welcome to CodeGolf.SE. Every question should be tagged to indicate the class of challenge that is being presented (i.e. if you mean the least characters you want [code-golf]), because we entertain other types of challenges as well, as long as they have an objective winning standard. I'll do this one for you. BTW--Nicely specified.
– dmckee --- ex-moderator kitten – 2012-03-16T00:50:20.7871How to work with leap yeras in answer? In 10 years then will be 2 days error. How long is month? – Hauleth – 2012-03-16T07:18:37.213
The month is as long as the calendar month. i.e. February 2012 has 29 days, February 2013 has 28. – Gaffi – 2012-03-16T10:36:46.433