1 /*
2  * hunt-time: A time library for D programming language.
3  *
4  * Copyright (C) 2015-2018 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 module hunt.time.util.Common;
13 
14 public import std.traits;
15 public import std.array;
16 
17 // import hunt.util.DateTime;
18 
19 // class System
20 // {
21 //     static long currentTimeMillis()
22 //     {
23 //         return DateTimeHelper.currentTimeMillis();
24 //     }
25 
26 //     static long currentTimeNsecs()
27 //     {
28 //         return convert!("hnsecs", "nsecs")(Clock.currStdTime() - (Date(1970, 1, 1) - Date.init).total!"hnsecs");
29 //     }
30 
31 //     // static string getSystemTimeZone()
32 //     // {
33 //     //     return DateTimeHelper.getSystemTimeZoneId();
34 //     // }
35 // }
36 
37 
38 string MakeGlobalVar(T)(string var, string init = null)
39 {
40     string str;
41     str ~= `__gshared ` ~ T.stringof ~ ` _` ~ var ~ `;`;
42     str ~= "\r\n";
43     if (init is null)
44     {
45         str ~= `public static ref ` ~ T.stringof ~ ` ` ~ var ~ `()
46             {
47                 static if(isAggregateType!(`~ T.stringof ~`))
48                 {
49                     if(_` ~ var ~ ` is null)
50                     {
51                         _`~ var ~ `= new ` ~ T.stringof ~ `();
52                     }
53                 }
54                 else static if(isArray!(`~ T.stringof ~ `))
55                 {
56                     if(_` ~ var ~ `.length == 0 )
57                     {
58                         _`~ var ~ `= new ` ~ T.stringof ~ `;
59                     }
60                 }
61                 else
62                 {
63                     if(_` ~ var ~ ` == `~ T.stringof.replace("[]","") ~`.init )
64                     {
65                         _`~ var ~ `= new ` ~ T.stringof ~ `();
66                     }
67                 }
68                 
69                 return _` ~ var ~ `;
70             }`;
71     }
72     else
73     {
74         str ~= `public static ref ` ~ T.stringof ~ ` ` ~ var ~ `()
75             {
76                 static if(isAggregateType!(`~ T.stringof ~`))
77                 {
78                     if(_` ~ var ~ ` is null)
79                     {
80                         _`~ var ~ `= ` ~ init ~ `;
81                     }
82                 }
83                 else static if(isArray!(`~ T.stringof ~ `))
84                 {
85                     if(_` ~ var ~ `.length == 0 )
86                     {
87                         _`~ var ~ `= ` ~ init ~ `;
88                     }
89                 }
90                 else
91                 {
92                     if(_` ~ var ~ ` == `~ T.stringof.replace("[]","") ~`.init )
93                     {
94                         _`~ var ~ `= ` ~ init ~ `;
95                     }
96                 }
97                
98                 return _` ~ var ~ `;
99             }`;
100     }
101 
102     return str;
103 }
104 
105