# How can Time be made to go backwards?

I would like to make a countdown timer, but cannot find a reliable method to make the DateList[] function reverse.

The not so robust code for the Digital Clock with the display of seconds follows:

digit[i_, xoffset_] := Module[{params},
params = Part[segmentParams, segmentPieces[[i + 1]]];
params = Map[# + {0, xoffset, 0, 0} &, params];
Graphics[makeSegment /@ params]];

makeSegment[params_] :=
Translate[
Rotate[Polygon[{{0, 0}, {params[[4]], 0}, {params[[4]] + 1/4,
1/4}, {params[[4]], 1/2}, {0, 1/2}, {-1/4, 1/4}}],
params[[1]] Degree], {params[[2]], params[[3]]}]
segmentParams = {{0, 0, 1.2, 1}, {90,-.6, .6, .6}, {90,1,.6,.6}, {0, 0, 0, 1},
{90,-.6,-.6,.6}, {90, 1,-.6,.6}, {0, 0,-1.2, 1}};
segmentPieces = {{1, 2, 3, 5, 6, 7}, {3, 6}, {1, 3, 4, 5, 7}, {1, 3, 4, 6, 7},
{2, 3, 4, 6}, {1, 2, 4, 6, 7}, {1, 2, 4, 5, 6, 7}, {1, 3, 6},
{1, 2, 3, 4, 5, 6, 7}, {1, 2, 3, 4, 6, 7}};
timer = Dynamic@Refresh[Show[{digit[Floor[DateList[][[6]]/10], 12],
digit[Mod[Floor@DateList[][[6]], 10], 15]}, ImageSize -> 26], UpdateInterval -> 1]


I say not so robust because after it's running, it has a tendency to stop. Not sure why yet, but none the less I would like to make it run backwards. I can use: RunScheduledTask to begin the timer and set an alarm but would like to show the time counting down.

• migrated to theoretical physics -- ;-) Jul 22, 2012 at 1:25
• @Mr.Wizard I wonder if he meant "backwards into the future" ;-) Jul 22, 2012 at 1:27
• There is too much code here and stress on digital display. I am also not really sure what the author wants. So I just added a question which may (or may not) be helpful in this case. mathematica.stackexchange.com/questions/8595/… Jul 22, 2012 at 2:25
• @Mr.Wizard Comes in handy when you just need another minute ;-) thanks! Jul 22, 2012 at 2:50

Replace your timer = .. by

tf = IntegerPart[AbsoluteTime[] + 60];

Dynamic@Refresh[
Show[{digit[#[[-2]], 12], digit[#[[-1]], 15]}, ImageSize -> 26] &@
IntegerDigits[1000 + tf - IntegerPart@AbsoluteTime[]],   UpdateInterval -> 1]


Edit

To force the countdown to stop after reaching zero, you could do something like:

tf = IntegerPart[AbsoluteTime[] + 10];
expired = False;
Dynamic@Refresh[
If[(! expired ) && # != {1, 0, 0},
Show[{digit[#[[-2]], 12], digit[#[[-1]], 15]}, ImageSize -> 26],
(expired = True; digit[0, 12])] &@
IntegerDigits[100 + tf - IntegerPart@AbsoluteTime[]],
UpdateInterval -> 1]

• Great solution. Thank you Jul 22, 2012 at 2:53