2
1
Write a program which takes the current time of the system clock, rounds to the nearest minute (you may choose how to round halves) and displays it formatted as the following:
A quarter past one in the morning.
A quarter to two in the afternoon.
Two o'clock in the afternoon.
Twenty-five minutes to three in the morning.
Twenty-seven minutes to seven in the evening.
One minute past twelve in the afternoon.
Twelve o'clock noon.
Twelve o'clock midnight.
Rules:
- 12:01am to 11:59am is deemed as morning.
- 12:01pm to 5:59pm is deemed as afternoon.
- 6:00pm to 11:59pm is deemed as evening.
- 15 minutes past the hour must be expressed as
A quarter pastthe hour - 30 minutes past the hour must be expressed as
Half pastthe hour - 45 minutes past the hour must be expressed as
A quarter tothe upcoming hour - On-the-hour times must be expressed as the hour
o'clock, with the addition of noon and midnight being expressed with the addition ofnoonormidnightrespectively. - Other times in hh:01 to hh:29 must be expressed as (number of minutes)
pastthe hour. - Other times in hh:31 to hh:59 must be expressed as (number of minutes)
tothe upcoming hour. - Twenty-one to twenty-nine must be hyphenated.
- The first letter of the output must be capitalised. The other letters must be lower-case.
It would be useful to provide a testing version of your code so that it can be tested without manipulating the system clock.
2Let's see what you got... - The specification is still a bit vague. E.g. what about
Fifteen minutes past oneorFourty-five minutes past onefor the first two examples? – Howard – 2013-12-10T07:57:46.0931I agree with Howard: there's a lot of dialectal variation here. To ensure that the contest is about golfing you need a complete spec. You also need to address rounding because the time is rarely an integer number of minutes past midnight. – Peter Taylor – 2013-12-10T08:39:54.790
What? Noon is noon, and midnight is midnight. I suggest those times read "Twelve o'clock noon" and "Twelve o'clock midnight". Noon is not afternoon, or 0=1. – boothby – 2013-12-10T09:21:39.180
Okay, so what do I print at 3:30 PM? Do I have to say "half past three in the afternoon"? – Doorknob – 2013-12-10T13:15:30.610
I'm voting to close until the spec is clarified to avoid more people posting solutions which might have to be withdrawn for not meeting the clarified spec. – Peter Taylor – 2013-12-10T14:23:43.883
I join @PeterTaylor, and suggest passing it through the sandbox
– ugoren – 2013-12-10T14:45:46.850@boothby As soon as a clock hits 12:00 noon, it registers as a PM time, as does a clock hitting 12:00 midnight registers as an AM time... – WallyWest – 2013-12-10T23:35:36.203
Any clock that exhibits that behavior sucks. In my humble opinion or something. – boothby – 2013-12-11T03:47:46.280
so, "thirty minutes past twelve in the morning" is a valid output? – John Dvorak – 2013-12-11T21:57:46.667
I thought I had put the 15,30,45 minute rules in...? They must have not saved...
Updated... – WallyWest – 2013-12-11T22:02:22.300