2020-06-24 13:53:18 +00:00
|
|
|
import std.algorithm;
|
|
|
|
import std.array;
|
2020-06-24 08:08:28 +00:00
|
|
|
import std.conv;
|
|
|
|
import std.datetime;
|
|
|
|
|
|
|
|
import dyaml;
|
|
|
|
|
|
|
|
string toHumanString(DateTime value) {
|
2020-06-27 22:43:15 +00:00
|
|
|
return to!string(value.day) ~ "-" ~ to!string(ubyte(value.month)) ~ "-" ~ to!string(value.year);
|
2020-06-24 08:08:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
T getOr(T)(Node node, string key, T or) {
|
|
|
|
if (key in node) {
|
2020-06-24 17:57:04 +00:00
|
|
|
try {
|
|
|
|
return node[key].get!T;
|
|
|
|
} catch (Exception e) {
|
|
|
|
return or;
|
|
|
|
}
|
2020-06-24 08:08:28 +00:00
|
|
|
} else {
|
|
|
|
return or;
|
|
|
|
}
|
|
|
|
}
|
2020-06-24 13:53:18 +00:00
|
|
|
|
|
|
|
T[] getArray(T)(Node node, string key, T[] or = []) {
|
|
|
|
try {
|
|
|
|
return node.getOr!(Node[])(key, [])
|
|
|
|
.map!(x => x.as!T).array;
|
|
|
|
} catch (NodeException e) {
|
|
|
|
return or;
|
|
|
|
}
|
|
|
|
}
|