Skip to content

Commit

Permalink
Work on unixtime.d
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Martinsson committed Nov 11, 2014
1 parent 9f916d8 commit f5da94d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions unixtime.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ import std.conv;
* Print current unix time stamp, or convert command line arguments from unix
* time stamp into human readable time.
*/
void main(string[] args) {
int main(string[] args) {
// Handle the simple case first.
if (args.length <= 1) {
writeln(Clock.currTime().toUnixTime);
return;
return 0;
}

foreach (input; args[1 .. $]) {
immutable unixTime = parse!long(input);
immutable t = SysTime(unixTimeToStdTime(unixTime));

writeln(t.toISOExtString());
try {
foreach (input; args[1 .. $]) {
immutable unixTime = parse!long(input);
immutable t = SysTime(unixTimeToStdTime(unixTime));
writeln(t.toISOExtString());
}
} catch (std.conv.ConvException exc) {
stderr.writeln("Could not parse input as unix time stamp.");
stderr.writeln("Exception: ", exc.msg);
return 1;
}

return 0;
}

0 comments on commit f5da94d

Please sign in to comment.