Add tags

Add tags to the following comment

使用例も書かないとダメですね。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import std.conv;
import std.date;
import std.stdio;

string DateEx(string datetime, int tdelta_in_secs)
{
    d_time t = std.date.parse(datetime);
    d_time new_datetime = t + tdelta_in_secs * std.date.TicksPerSecond;
    return std.date.toString(new_datetime);
}
unittest {
    assert(DateEx("Mon Sep 01 13:00:00 GMT+0900 2008", -3600) ==
        "Mon Sep 01 12:00:00 GMT+0900 2008");
    assert(DateEx("Mon Sep 01 13:00:00 GMT+0900 2008", 3600) ==
        "Mon Sep 01 14:00:00 GMT+0900 2008");
}

void main(string[] args)
{
    string datetime;
    int tdelta_in_secs;
    if (args.length == 3) {
        datetime = args[1];
        tdelta_in_secs = toInt(args[2]);
    }
    else {
        d_time now = std.date.getUTCtime;
        datetime = std.date.toString(now);
        tdelta_in_secs = toInt(args[1]);
    }
    writefln("%s", DateEx(datetime, tdelta_in_secs));
}

// eof

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...