This question already has an answer here:

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

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]

Or if the input starts with a - then subtract that time:

ruby time.rb -2[: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.

  1. The program has to get the date and it is not provided by the user
  2. The input has many different formats 01:00, 1:00, 1, +1, -1, 1:23 etc.

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 HH:MM

marked as duplicate by Beta Decay, Shaggy, feersum, Erik the Outgolfer, Toto Jun 27 '17 at 9:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ Sorry for the confusion. I judged too quickly. I have reverted my edits. \$\endgroup\$ – Leaky Nun Jun 27 '17 at 9:11
  • \$\begingroup\$ @LeakyNun No worries. I was just about to message for clarification. Being new to the community I thought I misunderstood something :) \$\endgroup\$ – KNejad Jun 27 '17 at 9:12
  • \$\begingroup\$ Can we output the seconds too or should it be only hours:minutes ? \$\endgroup\$ – Dada Jun 27 '17 at 9:22
  • \$\begingroup\$ @Dada Only hours and minutes. The output has to be exactly like I showed in my examples. \$\endgroup\$ – KNejad Jun 27 '17 at 9:26
  • \$\begingroup\$ @BetaDecay Please see my edit concerning the duplicate question. \$\endgroup\$ – KNejad Jun 27 '17 at 9:27

Browse other questions tagged or ask your own question.