# Increment The Time

Every digital clock contains a small creature that has to advance the time every minute [citation needed]. Due to the popularty of digital clocks and the popularity of catching them in the wild, they are nearly extinct in nature which is why in this challenge we try to automate this task:

Given your string of a given time in the 24h format, the task is to advance this time by one minute.

## Details

• Both the input and output must be strings.
• The time is given as a five character string.
• Both the hour and the minutes are given as a two digit number: if the number is below 10, there will be a leading zero.
• The two numbers are separated by a colon.

## Examples

Input    Output
00:00    00:01
00:02    00:03
05:55    05:56
09:59    10:00
12:49    12:50
20:05    20:06
23:59    00:00

• Congratulations on finding a challenge in which Excel beats Jelly!
– ojdo
Oct 6, 2021 at 13:58
• [citation needed] 🤣 Oct 7, 2021 at 23:53
• Ref: Pratchett. In Discworld, imps usually do that sort of thing. “Good Morning, Insert Name Here! I am the Dis-Organizer Mark Five, the Gooseberry™. How may I—” Oct 8, 2021 at 3:35

# QBasic, 132 129 bytes

INPUT t$i=6 1i=i-1+f x=ASC(MID$(t$,i))-47 f=i=4 x=x<10+f*4AND x MID$(t$,i,1)=CHR$(x+48)
IF x=0GOTO 1
IF"24"<t$THEN t$="00:00
?t$ Try it here! ### Explanation ' Read the input time into t$
INPUT t$' i is the index of the current digit, starting one digit to the right of the string i = 6 ' Label 1 is the start of the loop 1 ' Subtract 1 from i, and subtract an additional 1 if f is set (see below) i = i - 1 + f ' x is the current digit plus 1 x = ASC(MID$(t$, i)) - 47 ' f is true (-1) only when i = 4 f = (i = 4) ' If x = 10, or if f is true and x = 6, set x to 0; otherwise, leave it unchanged x = x < (10 + f * 4) AND x ' Write that digit back into the string t$ at the current position
MID$(t$, i, 1) = CHR$(x + 48) ' Loop if this digit wrapped around to 0 IF x = 0 THEN GOTO 1 ' Special case: when t$ is 24:00, wrap around to 00:00
IF "24" < t$THEN t$ = "00:00"
' Print the final result
PRINT t$ # Red, 85 bytes func[s][p: func[t][pad/left/with t 2 #"0"]s:(load s)+ 0:1 rejoin[p s/1 % 24":"p s/2]]  Try it online! # 05AB1E, 26 bytes ':¡©59%(d+24%®>60%‚т‰J':ý  Try it online! I am sorry. -1 byte fix thanks to Kevin Cruijsen!! • You're missing a trailing ':ý, since the output must be a string in a similar format as well. You can remove the ï for -1; golf the D, .À+, and s to ©, +, and ® for -2; and the т+€¦ to т‰J for another -1. (PS: We posted our 05AB1E answers almost simultaneously.) Oct 5, 2021 at 9:16 • @KevinCruijsen thanks for the 0 byte fix!!! Oct 5, 2021 at 9:20 • -1 actually. ;) You forgot to remove the ï. Integers/strings are interchangeable in 05AB1E, so explicit casting is almost never necessary (unless you're sorting, or unless there is a bug). Oct 5, 2021 at 9:33 • @KevinCruijssen oh yes! Coercion is nice Oct 5, 2021 at 9:59 # Vyxal, 25 bytes 24ʁ60ʁẊƛƛS2↳ð0V;\:j;:?ḟ›i  Try it Online! What a mess. Handling 0-padding, and some slightly cursed vectorising, was a pain. 24ʁ # 0...23 60ʁ # 0...59 Ẋ # Cartesian product ƛ ; # Map... ƛ ; # Map... S # Stringify 2↳ # pad left to length 2 (with spaces, we really need zfill) ð0V # Replace spaces with zeroes \:j # Join by colons ?ḟ # Find input in this › # Increment : i # Index into this  • I have an idea for the 0 padding, add each by 100 then cut the head. You can implement in vyxal Oct 6, 2021 at 17:16 # Twue, 123 bytes a::>* :59$::=$:00 23$:::=00:
0$::=1 1$::=2
2$::=3 3$::=4
4$::=5 5$::=6
6$::=7 7$::=8
8$::=9 9$::=$0 ^_::=!_^ !_::~_ ::= ^a$

Try it on the website!

Works by taking input through a, having two replacement rules governing roll-over (:59 -> :00 and add 1, 23$: -> 00:). Then, we have a rule for incrementing, rolling over only when we increment a 9. After that, we output everything. # Haskell, 130 bytes import Text.Printf f(a:b:c:d)|[m,h]<-map read[d,a:[b]]::[Int]=[mod(m+1)60,mod(h+mdiv59)24] g s|[m,h]<-f s=printf"%0.2d:%0.2d"h m  Try it online! Haskell is missing, hope to see a better one because I feel like mine is a bit messy • f reads the input string and increments the values properly • g prints/converts back values using C-like formatting of Text.Printf #### Slim Sharp 46 Bytes P(T.Parse(t).AddMinutes(1).ToString("HH:mm"));  Try it Online! ##### How it Works P( // Write the contents to the console. T.Parse(t) // Parse the input as a date time object. .ToString( // Output the date time object as a string. "HH:mm" // Format the output in 24 hour time with hours and minutes only. )); // End statement.  # Wolfram Language (Mathematica), 47 bytes StringTake[ToString@DatePlus[#,1/1440],-{8,4}]&  Try it online! # Python 3.8, 66 bytes lambda t:f'{(int(t[:2])+((m:=(int(t[3:])+1)%60)<1))%24:02}:{m:02}'  Try it online! A slightly different approach to @dingledooper's answer (and 2 bytes longer 😕), but the same basic idea. • You can save two bytes on parentheses by using -~ to increment: Try it online! Sep 21, 2022 at 16:19 # PowerShell, 45 bytes (Get-date$x).AddMinutes(1).ToString("HH:mm")

Try it online

• Welcome to Code Golf! Nice answer. Oct 14, 2021 at 19:29

# Visual Basic, 49 bytes (format command)

Dim ins$, out$

ins = "20:21"
out = Format$(DateAdd("n", 1, TimeValue(ins)), "hh:mm")  Uses internal time functions. • Welcome to Code golf, and nice first answer! Here, we usually require that answers be golfed, which you can do by removing whitespace and shortening variable names - also check out our Tips for golfing in Visual Basic page. You could add a TIO link so others can test your code online. Oct 14, 2021 at 20:40 # Perl 5-F:, 67 64 bytes 63 60 bytes for code; +4 bytes for -F switch -3 bytes thanks to erlik @F=++$F,0if++$F>59;$F*="@F"<24;printf"%02d:%02d",@F


Try it online!

Ungolfed version:

if (++$F > 59) { @F = (++$F, 0);
}
$F *= "@F" < 24; printf("%02d:%02d", @F);  • You can make it 3 chars shorter by replacing the second statement with$F*="@F"<24 Oct 14, 2021 at 19:37

# Zsh builtins (no date utils), 66 bytes

Reinventing the wheel... Try it Online!

m=$[(${1:3}+1)%60]
printf %02d:%02d $[(${1:0:2}+(m==0?1:0))%24] $m  # Python 3.8, 86 bytes Little late on this one, but haven't done code golf in a long time and was bored :) EDIT: -8 bytes lambda s:'%02d:%02d'%([x:=int(s[:2]),[x+1,0][x>22]][(y:=int(s[3:])+1)>59],[y,0][y>59])  Try it online! # Python 3.8 (pre-release), 88 bytes def f(s):h,m=int(s[:2]),int(s[-2:]);m=(m+1)%60;m or(h:=(h+1)%24);return f'{h:02}:{m:02}'  Try it online! Very straightforward solution here. Nowhere near competitive and nothing novel, but I enjoyed this! I learned a new trick along the way: m or(h:=(h+1)%24) is equivalent to if m<1:h=(h+1)%24 and the same length, but allows the whole function to be collapsed into one line with semicolons, saving four characters. Without that, this would be four lines. def f(s): h,m=int(s[:2]),int(s[-2:]);m=(m+1)%60 if m<1:h=(h+1)%24 return f'{h:02}:{m:02}'  Other fun equivalences I learned today: m=(m+1)%60 is the same length as m+=1;m%=60 return f'{h:02}:{m:02}' is the same length as return'%02d:%02d'%(h,m) • Another fun thing: -~m is equivalent to m+1, except it doesn't need the parentheses. Also, s[-2:] can be s[3:]. Try it online! Sep 21, 2022 at 5:16 In Go you can do this 153 bytes package main import ( "fmt" "time" "os" ) func main() { t,_ := time.Parse(15:04, os.Args) fmt.Print(t.Add(time.Minute).Format(15:04)) }  Try it online • Welcome to the site. I'm a little confused as to how you are counting bytes here. The first block is ~174 bytes and the second block is 78 bytes, so I'm not sure what code you are counting. I also don't think either of these take any input? They seem to do the operation on in the first case a fixed string and in the second case it seems to expect the input in a variable named i. You can see a variety of ways you can take input here. Oct 15, 2021 at 8:19 • I was counting just by selecting code, and seeing whatever Sublime gave me. About input output, also wasn't sure how to deliver data. I fixed my answer to take input from cmd line. – Slav Oct 15, 2021 at 9:08 • Hm. I have no idea what sublime is doing. Maybe it isn't counting whitespace or something? You can use TIO to get an accurate score link. We also have a tips question where you can get tips on golfing in go. I can already see that there are some ways that you could shorten this so try looking at that and playing around with whitespace. Oct 15, 2021 at 9:15 # K, 9 bytes -3!1+-5!x  # Q, 14 bytes: string 1+"U"$x


## Explanation

Q is evaluated from right to left:

         "U"$x // Cast input x into the minutes types 1+ // Add one (automatically casted into minutes) string // Cast to string  For this specific input string, the casting part can also be written as parse x  Resulting in a quite readable 16 bytes: string 1+parse x  Replacing string and parse with the K internal function equivalents (-3! and -5! respectively) we get: -3!1+-5!x • Minor caveat: input 23:59 will yield 24:00 output, not 00:00. This can be fixed adding mod: -3!1440 mod 1+-5!x (+9 bytes). Oct 27, 2021 at 0:58 # Python 3.8, 118 114 113 112 bytes New version i=input();t=[-1]*59+;h=*24+[-23];a=int(i[:2]);b=int(i[3:]);print(f'{a+h[a+int(t[b]/30)]:02}:{b-t[b]:02}')  Old version: i=input();t=(1,0)*59+(-59,1);h=*24+[-23];a=int(i[:2]);b=int(i[3:]);print(f'{a+h[a+t[b*2+1]]:02}:{b+t[b*2]:02}')  Older version: i=input();t=[(1,0)]*59+[(-59,1)];h=*23+[-24];a=int(i[:2]);b=int(i[3:]);print(f'{a+h[a]+t[b]:02}:{b+t[b]:02}')  Try it here! Cleaner version i=input() t=*59+[-59] h=*24+[-23] a=int(i[:2]) b=int(i[3:]) print(f'{a+h[a+int(t[b]/-30)]:02}:{b+t[b]:02}')  A somewhat dumb but interesting approach I tried, I am pretty sure I can probably shorten this somewhere by 15-20~ Bytes, I will have to check it again later. The method uses two lookup arrays to figure out what to do with the date. Its worse than the other answers, but I thought its interesting enough to leave in after golfing it a bit. I am not really good at this yet haha. Some thoughts that would be interesting to discuss, I see a few places where I can see an improvement being possible, but not sure how: 1. In the part (a=int(i[:2]);b=int(i[3:]); this saves a number of bytes since I use a and b alot, but its still a very... ugly solution for the lack of a better word, I looked into a,b=map(int,i.split(":")) which looks neater but unfortunately has the exact same size. I am still looking for a better solution here though. 2. I really hate how the lists/tuples are initialized, must be a better way.. Edit: I legitimately have no idea how I came up with this madness, but some weird maths helped me remove an extra byte, somehow haha... I am certain I can push this further later.. Dang, just as I posted this I thought of a simple change with the signs that did save me another byte. # Knight (v2.0-alpha), 70 bytes ;=t+1+*+0=iP60Gi 3 2O++G=x+'0'%/t 60 24-Lx 2 2':'(G=x+'0'%t 60-Lx 2 2)  Try it online! • you don't need the parens (btw you can use the minify button to remove al the excess whitespace and parens and stuff) Sep 21, 2022 at 18:44 • i was gonna suggest +0 => E but i guess that's not part of the spec anymore Sep 21, 2022 at 18:45 # Scala, 106 bytes Golfed version. Try it online! def f(s:String)={val g=DateTimeFormatter.ofPattern("HH:mm");LocalTime.parse(s,g).plusMinutes(1).format(g)}  Ungolfed vesion. Try it online! import java.time._ import java.time.format.DateTimeFormatter object Main { def f(s: String): String = { val formatter = DateTimeFormatter.ofPattern("HH:mm") val time = LocalTime.parse(s, formatter) val newTime = time.plusMinutes(1) newTime.format(formatter) } def main(args: Array[String]): Unit = { val s = Array("00:00", "00:02", "05:55", "09:59", "12:49", "20:05", "23:59") val r = Array("00:01", "00:03", "05:56", "10:00", "12:50", "20:06", "00:00") for (i <- s.indices) { val result = f(s(i)) println(s"${s(i)} => $result (should be: '${r(i)}')")
}
}
}

`