1 /** 2 * Time string formatting and such. 3 * 4 * License: 5 * This Source Code Form is subject to the terms of 6 * the Mozilla Public License, v. 2.0. If a copy of 7 * the MPL was not distributed with this file, You 8 * can obtain one at http://mozilla.org/MPL/2.0/. 9 * 10 * Authors: 11 * Vladimir Panteleev <vladimir@thecybershadow.net> 12 */ 13 14 module ae.utils.time; 15 16 public import ae.utils.time.common; 17 public import ae.utils.time.format; 18 public import ae.utils.time.fpdur; 19 public import ae.utils.time.parse; 20 public import ae.utils.time.parsedur; 21 22 // *************************************************************************** 23 24 import std.datetime; 25 26 alias StdTime = typeof(SysTime.init.stdTime); // long 27 28 /// Like SysTime.stdTime. 29 @property StdTime stdTime(Duration d) 30 { 31 return d.total!"hnsecs"(); 32 } 33 34 @property bool empty(Duration d) 35 { 36 return !d.stdTime; 37 } 38 39 /// Workaround SysTime.fracSecs only being available in 2.067, 40 /// and SysTime.fracSec becoming deprecated in the same version. 41 static if (!is(typeof(SysTime.init.fracSecs))) 42 @property Duration fracSecs(SysTime s) 43 { 44 enum hnsecsPerSecond = convert!("seconds", "hnsecs")(1); 45 return hnsecs(s.stdTime % hnsecsPerSecond); 46 } 47 48 /// As above, for Duration.split and Duration.get 49 static if (!is(typeof(Duration.init.split!()))) 50 @property auto split(units...)(Duration d) 51 { 52 static struct Result 53 { 54 mixin("long " ~ [units].join(", ") ~ ";"); 55 } 56 57 Result result; 58 foreach (unit; units) 59 { 60 static if (is(typeof(d.get!unit))) // unit == "msecs" || unit == "usecs" || unit == "hnsecs" || unit == "nsecs") 61 long value = d.get!unit(); 62 else 63 long value = mixin("d.fracSec." ~ unit); 64 mixin("result." ~ unit ~ " = value;"); 65 } 66 return result; 67 } 68 69 // *************************************************************************** 70 71 // fpdur conflict test 72 static assert(1.5.seconds == 1500.msecs);