This question already has an answer here:
- Change the Timezone 12 answers
This challenge is related to a project I did last year (in Ruby). To make it more fun I decided to do it in as few bytes as possible. I didn't know about code golf back then so now that I found out about it and found this community I was wondering if anybody can beat me :)
The program should return the current time if no input is given
ruby time.rb 12:24
Or if you enter a time as a parameter it should return the time it will be in so many hours/minutes (pretend the time is 12:24) (the parts in
 are optional):
ruby time.rb [+]2[:12] 14:36
Or if the input starts with a
- then subtract that time:
ruby time.rb -2[:12] 10:12
Of course if you don't include the
:12 then it will only subtract the hours.
In Ruby I managed to get it at 144 bytes.
Of course you can do this in any language you like. However I would be happy to see if anybody can do any better in Ruby.
Yes it is similar to this challenge. However I think it is different in a couple of ways.
- The program has to get the date and it is not provided by the user
- The input has many different formats
I think these make it different enough but if you disagree then I will happily let go and allow it to be marked as duplicate.
- You must support all input formats I showed.
- You are allowed to use any method to calculate the time (except for asking the user)
- The output format must be