mirror of
https://github.com/dlang/phobos.git
synced 2025-05-03 16:40:48 +03:00
Removed the deprecated std.date.
Also removed std.datebase, std.dateparse, and std.gregorian.
This commit is contained in:
parent
7a2da1a489
commit
95b3fb81ad
8 changed files with 13 additions and 2535 deletions
13
posix.mak
13
posix.mak
|
@ -156,13 +156,12 @@ MAIN = $(ROOT)/emptymain.d
|
||||||
# Stuff in std/
|
# Stuff in std/
|
||||||
STD_MODULES = $(addprefix std/, algorithm array ascii base64 bigint \
|
STD_MODULES = $(addprefix std/, algorithm array ascii base64 bigint \
|
||||||
bitmanip compiler complex concurrency container contracts conv \
|
bitmanip compiler complex concurrency container contracts conv \
|
||||||
cpuid cstream ctype csv date datetime datebase dateparse demangle \
|
cpuid cstream ctype csv datetime demangle encoding exception \
|
||||||
encoding exception file format functional getopt gregorian \
|
file format functional getopt json loader math mathspecial md5 \
|
||||||
json loader math mathspecial md5 metastrings mmfile numeric \
|
metastrings mmfile numeric outbuffer parallelism path perf \
|
||||||
outbuffer parallelism path perf process random range regex \
|
process random range regex regexp signals socket socketstream \
|
||||||
regexp signals socket socketstream stdint stdio stdiobase \
|
stdint stdio stdiobase stream string syserror system traits \
|
||||||
stream string syserror system traits typecons typetuple uni \
|
typecons typetuple uni uri utf variant xml zip zlib)
|
||||||
uri utf variant xml zip zlib)
|
|
||||||
|
|
||||||
STD_NET_MODULES = $(addprefix std/net/, isemail curl)
|
STD_NET_MODULES = $(addprefix std/net/, isemail curl)
|
||||||
|
|
||||||
|
|
1218
std/date.d
1218
std/date.d
File diff suppressed because it is too large
Load diff
|
@ -1,25 +0,0 @@
|
||||||
// Written in the D programming language.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The only purpose of this module is to do the static construction for
|
|
||||||
* std.date, to eliminate cyclic construction errors.
|
|
||||||
*
|
|
||||||
* Copyright: Copyright Digital Mars 2000 - 2009.
|
|
||||||
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
|
|
||||||
* Authors: $(WEB digitalmars.com, Walter Bright)
|
|
||||||
* Source: $(PHOBOSSRC std/_datebase.d)
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright Digital Mars 2000 - 2009.
|
|
||||||
* Distributed under the Boost Software License, Version 1.0.
|
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
module std.datebase;
|
|
||||||
|
|
||||||
extern(C) void std_date_static_this();
|
|
||||||
|
|
||||||
shared static this()
|
|
||||||
{
|
|
||||||
std_date_static_this();
|
|
||||||
}
|
|
784
std/dateparse.d
784
std/dateparse.d
|
@ -1,784 +0,0 @@
|
||||||
// Written in the D programming language.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $(RED Deprecated. It will be removed in March 2012.
|
|
||||||
* Please use std.datetime instead.)
|
|
||||||
*
|
|
||||||
* dateparse module.
|
|
||||||
*
|
|
||||||
* Copyright: Copyright Digital Mars 2000 - 2009.
|
|
||||||
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
|
|
||||||
* Authors: $(WEB digitalmars.com, Walter Bright)
|
|
||||||
* Source: $(PHOBOSSRC std/_dateparse.d)
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright Digital Mars 2000 - 2009.
|
|
||||||
* Distributed under the Boost Software License, Version 1.0.
|
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
module std.dateparse;
|
|
||||||
|
|
||||||
private
|
|
||||||
{
|
|
||||||
import std.algorithm, std.string;
|
|
||||||
import std.c.stdlib;
|
|
||||||
import std.date;
|
|
||||||
}
|
|
||||||
|
|
||||||
deprecated:
|
|
||||||
|
|
||||||
//debug=dateparse;
|
|
||||||
|
|
||||||
class DateParseError : Error
|
|
||||||
{
|
|
||||||
this(string s)
|
|
||||||
{
|
|
||||||
super("Invalid date string: " ~ s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct DateParse
|
|
||||||
{
|
|
||||||
void parse(string s, out Date date)
|
|
||||||
{
|
|
||||||
this = DateParse.init;
|
|
||||||
|
|
||||||
//version (Windows)
|
|
||||||
buffer = (cast(char *)alloca(s.length))[0 .. s.length];
|
|
||||||
//else
|
|
||||||
//buffer = new char[s.length];
|
|
||||||
|
|
||||||
debug(dateparse) printf("DateParse.parse('%.*s')\n", s);
|
|
||||||
if (!parseString(s))
|
|
||||||
{
|
|
||||||
goto Lerror;
|
|
||||||
}
|
|
||||||
|
|
||||||
/+
|
|
||||||
if (year == year.init)
|
|
||||||
year = 0;
|
|
||||||
else
|
|
||||||
+/
|
|
||||||
debug(dateparse)
|
|
||||||
printf("year = %d, month = %d, day = %d\n%02d:%02d:%02d.%03d\nweekday = %d, tzcorrection = %d\n",
|
|
||||||
year, month, day,
|
|
||||||
hours, minutes, seconds, ms,
|
|
||||||
weekday, tzcorrection);
|
|
||||||
if (
|
|
||||||
year == year.init ||
|
|
||||||
(month < 1 || month > 12) ||
|
|
||||||
(day < 1 || day > 31) ||
|
|
||||||
(hours < 0 || hours > 23) ||
|
|
||||||
(minutes < 0 || minutes > 59) ||
|
|
||||||
(seconds < 0 || seconds > 59) ||
|
|
||||||
(tzcorrection != int.min &&
|
|
||||||
((tzcorrection < -2300 || tzcorrection > 2300) ||
|
|
||||||
(tzcorrection % 10)))
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Lerror:
|
|
||||||
throw new DateParseError(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ampm)
|
|
||||||
{ if (hours > 12)
|
|
||||||
goto Lerror;
|
|
||||||
if (hours < 12)
|
|
||||||
{
|
|
||||||
if (ampm == 2) // if P.M.
|
|
||||||
hours += 12;
|
|
||||||
}
|
|
||||||
else if (ampm == 1) // if 12am
|
|
||||||
{
|
|
||||||
hours = 0; // which is midnight
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (tzcorrection != tzcorrection.init)
|
|
||||||
// tzcorrection /= 100;
|
|
||||||
|
|
||||||
if (year >= 0 && year <= 99)
|
|
||||||
year += 1900;
|
|
||||||
|
|
||||||
date.year = year;
|
|
||||||
date.month = month;
|
|
||||||
date.day = day;
|
|
||||||
date.hour = hours;
|
|
||||||
date.minute = minutes;
|
|
||||||
date.second = seconds;
|
|
||||||
date.ms = ms;
|
|
||||||
date.weekday = weekday;
|
|
||||||
date.tzcorrection = tzcorrection;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
int year = int.min; // our "nan" Date value
|
|
||||||
int month; // 1..12
|
|
||||||
int day; // 1..31
|
|
||||||
int hours; // 0..23
|
|
||||||
int minutes; // 0..59
|
|
||||||
int seconds; // 0..59
|
|
||||||
int ms; // 0..999
|
|
||||||
int weekday; // 1..7
|
|
||||||
int ampm; // 0: not specified
|
|
||||||
// 1: AM
|
|
||||||
// 2: PM
|
|
||||||
int tzcorrection = int.min; // -1200..1200 correction in hours
|
|
||||||
|
|
||||||
string s;
|
|
||||||
int si;
|
|
||||||
int number;
|
|
||||||
char[] buffer;
|
|
||||||
|
|
||||||
enum DP : byte
|
|
||||||
{
|
|
||||||
err,
|
|
||||||
weekday,
|
|
||||||
month,
|
|
||||||
number,
|
|
||||||
end,
|
|
||||||
colon,
|
|
||||||
minus,
|
|
||||||
slash,
|
|
||||||
ampm,
|
|
||||||
plus,
|
|
||||||
tz,
|
|
||||||
dst,
|
|
||||||
dsttz,
|
|
||||||
}
|
|
||||||
|
|
||||||
DP nextToken()
|
|
||||||
{ int nest;
|
|
||||||
uint c;
|
|
||||||
int bi;
|
|
||||||
DP result = DP.err;
|
|
||||||
|
|
||||||
//printf("DateParse::nextToken()\n");
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
assert(si <= s.length);
|
|
||||||
if (si == s.length)
|
|
||||||
{ result = DP.end;
|
|
||||||
goto Lret;
|
|
||||||
}
|
|
||||||
//printf("\ts[%d] = '%c'\n", si, s[si]);
|
|
||||||
switch (s[si])
|
|
||||||
{
|
|
||||||
case ':': result = DP.colon; goto ret_inc;
|
|
||||||
case '+': result = DP.plus; goto ret_inc;
|
|
||||||
case '-': result = DP.minus; goto ret_inc;
|
|
||||||
case '/': result = DP.slash; goto ret_inc;
|
|
||||||
case '.':
|
|
||||||
version(DATE_DOT_DELIM)
|
|
||||||
{
|
|
||||||
result = DP.slash;
|
|
||||||
goto ret_inc;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
si++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret_inc:
|
|
||||||
si++;
|
|
||||||
goto Lret;
|
|
||||||
|
|
||||||
case ' ':
|
|
||||||
case '\n':
|
|
||||||
case '\r':
|
|
||||||
case '\t':
|
|
||||||
case ',':
|
|
||||||
si++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '(': // comment
|
|
||||||
nest = 1;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
si++;
|
|
||||||
if (si == s.length)
|
|
||||||
goto Lret; // error
|
|
||||||
switch (s[si])
|
|
||||||
{
|
|
||||||
case '(':
|
|
||||||
nest++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ')':
|
|
||||||
if (--nest == 0)
|
|
||||||
goto Lendofcomment;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Lendofcomment:
|
|
||||||
si++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
number = 0;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
if (si == s.length)
|
|
||||||
// c cannot be undefined here
|
|
||||||
break;
|
|
||||||
c = s[si];
|
|
||||||
if (!(c >= '0' && c <= '9'))
|
|
||||||
break;
|
|
||||||
result = DP.number;
|
|
||||||
number = number * 10 + (c - '0');
|
|
||||||
si++;
|
|
||||||
}
|
|
||||||
if (result == DP.number)
|
|
||||||
goto Lret;
|
|
||||||
|
|
||||||
bi = 0;
|
|
||||||
bufloop:
|
|
||||||
while (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
|
|
||||||
{
|
|
||||||
if (c < 'a') // if upper case
|
|
||||||
c += cast(uint)'a' - cast(uint)'A'; // to lower case
|
|
||||||
buffer[bi] = cast(char)c;
|
|
||||||
bi++;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
si++;
|
|
||||||
if (si == s.length)
|
|
||||||
break bufloop;
|
|
||||||
c = s[si];
|
|
||||||
} while (c == '.'); // ignore embedded '.'s
|
|
||||||
}
|
|
||||||
result = classify(buffer[0 .. bi].idup);
|
|
||||||
goto Lret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Lret:
|
|
||||||
//printf("-DateParse::nextToken()\n");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
DP classify(string buf)
|
|
||||||
{
|
|
||||||
struct DateID
|
|
||||||
{
|
|
||||||
string name;
|
|
||||||
DP tok;
|
|
||||||
short value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static immutable DateID dateidtab[] =
|
|
||||||
[
|
|
||||||
{ "january", DP.month, 1},
|
|
||||||
{ "february", DP.month, 2},
|
|
||||||
{ "march", DP.month, 3},
|
|
||||||
{ "april", DP.month, 4},
|
|
||||||
{ "may", DP.month, 5},
|
|
||||||
{ "june", DP.month, 6},
|
|
||||||
{ "july", DP.month, 7},
|
|
||||||
{ "august", DP.month, 8},
|
|
||||||
{ "september", DP.month, 9},
|
|
||||||
{ "october", DP.month, 10},
|
|
||||||
{ "november", DP.month, 11},
|
|
||||||
{ "december", DP.month, 12},
|
|
||||||
{ "jan", DP.month, 1},
|
|
||||||
{ "feb", DP.month, 2},
|
|
||||||
{ "mar", DP.month, 3},
|
|
||||||
{ "apr", DP.month, 4},
|
|
||||||
{ "jun", DP.month, 6},
|
|
||||||
{ "jul", DP.month, 7},
|
|
||||||
{ "aug", DP.month, 8},
|
|
||||||
{ "sep", DP.month, 9},
|
|
||||||
{ "sept", DP.month, 9},
|
|
||||||
{ "oct", DP.month, 10},
|
|
||||||
{ "nov", DP.month, 11},
|
|
||||||
{ "dec", DP.month, 12},
|
|
||||||
|
|
||||||
{ "sunday", DP.weekday, 1},
|
|
||||||
{ "monday", DP.weekday, 2},
|
|
||||||
{ "tuesday", DP.weekday, 3},
|
|
||||||
{ "tues", DP.weekday, 3},
|
|
||||||
{ "wednesday", DP.weekday, 4},
|
|
||||||
{ "wednes", DP.weekday, 4},
|
|
||||||
{ "thursday", DP.weekday, 5},
|
|
||||||
{ "thur", DP.weekday, 5},
|
|
||||||
{ "thurs", DP.weekday, 5},
|
|
||||||
{ "friday", DP.weekday, 6},
|
|
||||||
{ "saturday", DP.weekday, 7},
|
|
||||||
|
|
||||||
{ "sun", DP.weekday, 1},
|
|
||||||
{ "mon", DP.weekday, 2},
|
|
||||||
{ "tue", DP.weekday, 3},
|
|
||||||
{ "wed", DP.weekday, 4},
|
|
||||||
{ "thu", DP.weekday, 5},
|
|
||||||
{ "fri", DP.weekday, 6},
|
|
||||||
{ "sat", DP.weekday, 7},
|
|
||||||
|
|
||||||
{ "am", DP.ampm, 1},
|
|
||||||
{ "pm", DP.ampm, 2},
|
|
||||||
|
|
||||||
{ "gmt", DP.tz, +000},
|
|
||||||
{ "ut", DP.tz, +000},
|
|
||||||
{ "utc", DP.tz, +000},
|
|
||||||
{ "wet", DP.tz, +000},
|
|
||||||
{ "z", DP.tz, +000},
|
|
||||||
{ "wat", DP.tz, +100},
|
|
||||||
{ "a", DP.tz, +100},
|
|
||||||
{ "at", DP.tz, +200},
|
|
||||||
{ "b", DP.tz, +200},
|
|
||||||
{ "c", DP.tz, +300},
|
|
||||||
{ "ast", DP.tz, +400},
|
|
||||||
{ "d", DP.tz, +400},
|
|
||||||
{ "est", DP.tz, +500},
|
|
||||||
{ "e", DP.tz, +500},
|
|
||||||
{ "cst", DP.tz, +600},
|
|
||||||
{ "f", DP.tz, +600},
|
|
||||||
{ "mst", DP.tz, +700},
|
|
||||||
{ "g", DP.tz, +700},
|
|
||||||
{ "pst", DP.tz, +800},
|
|
||||||
{ "h", DP.tz, +800},
|
|
||||||
{ "yst", DP.tz, +900},
|
|
||||||
{ "i", DP.tz, +900},
|
|
||||||
{ "ahst", DP.tz, +1000},
|
|
||||||
{ "cat", DP.tz, +1000},
|
|
||||||
{ "hst", DP.tz, +1000},
|
|
||||||
{ "k", DP.tz, +1000},
|
|
||||||
{ "nt", DP.tz, +1100},
|
|
||||||
{ "l", DP.tz, +1100},
|
|
||||||
{ "idlw", DP.tz, +1200},
|
|
||||||
{ "m", DP.tz, +1200},
|
|
||||||
|
|
||||||
{ "cet", DP.tz, -100},
|
|
||||||
{ "fwt", DP.tz, -100},
|
|
||||||
{ "met", DP.tz, -100},
|
|
||||||
{ "mewt", DP.tz, -100},
|
|
||||||
{ "swt", DP.tz, -100},
|
|
||||||
{ "n", DP.tz, -100},
|
|
||||||
{ "eet", DP.tz, -200},
|
|
||||||
{ "o", DP.tz, -200},
|
|
||||||
{ "bt", DP.tz, -300},
|
|
||||||
{ "p", DP.tz, -300},
|
|
||||||
{ "zp4", DP.tz, -400},
|
|
||||||
{ "q", DP.tz, -400},
|
|
||||||
{ "zp5", DP.tz, -500},
|
|
||||||
{ "r", DP.tz, -500},
|
|
||||||
{ "zp6", DP.tz, -600},
|
|
||||||
{ "s", DP.tz, -600},
|
|
||||||
{ "wast", DP.tz, -700},
|
|
||||||
{ "t", DP.tz, -700},
|
|
||||||
{ "cct", DP.tz, -800},
|
|
||||||
{ "u", DP.tz, -800},
|
|
||||||
{ "jst", DP.tz, -900},
|
|
||||||
{ "v", DP.tz, -900},
|
|
||||||
{ "east", DP.tz, -1000},
|
|
||||||
{ "gst", DP.tz, -1000},
|
|
||||||
{ "w", DP.tz, -1000},
|
|
||||||
{ "x", DP.tz, -1100},
|
|
||||||
{ "idle", DP.tz, -1200},
|
|
||||||
{ "nzst", DP.tz, -1200},
|
|
||||||
{ "nzt", DP.tz, -1200},
|
|
||||||
{ "y", DP.tz, -1200},
|
|
||||||
|
|
||||||
{ "bst", DP.dsttz, 000},
|
|
||||||
{ "adt", DP.dsttz, +400},
|
|
||||||
{ "edt", DP.dsttz, +500},
|
|
||||||
{ "cdt", DP.dsttz, +600},
|
|
||||||
{ "mdt", DP.dsttz, +700},
|
|
||||||
{ "pdt", DP.dsttz, +800},
|
|
||||||
{ "ydt", DP.dsttz, +900},
|
|
||||||
{ "hdt", DP.dsttz, +1000},
|
|
||||||
{ "mest", DP.dsttz, -100},
|
|
||||||
{ "mesz", DP.dsttz, -100},
|
|
||||||
{ "sst", DP.dsttz, -100},
|
|
||||||
{ "fst", DP.dsttz, -100},
|
|
||||||
{ "wadt", DP.dsttz, -700},
|
|
||||||
{ "eadt", DP.dsttz, -1000},
|
|
||||||
{ "nzdt", DP.dsttz, -1200},
|
|
||||||
|
|
||||||
{ "dst", DP.dst, 0},
|
|
||||||
];
|
|
||||||
|
|
||||||
//message(DTEXT("DateParse::classify('%s')\n"), buf);
|
|
||||||
|
|
||||||
// Do a linear search. Yes, it would be faster with a binary
|
|
||||||
// one.
|
|
||||||
for (uint i = 0; i < dateidtab.length; i++)
|
|
||||||
{
|
|
||||||
if (cmp(dateidtab[i].name, buf) == 0)
|
|
||||||
{
|
|
||||||
number = dateidtab[i].value;
|
|
||||||
return dateidtab[i].tok;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DP.err;
|
|
||||||
}
|
|
||||||
|
|
||||||
int parseString(string s)
|
|
||||||
{
|
|
||||||
int n1;
|
|
||||||
int dp;
|
|
||||||
int sisave;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
//message(DTEXT("DateParse::parseString('%ls')\n"), s);
|
|
||||||
this.s = s;
|
|
||||||
si = 0;
|
|
||||||
dp = nextToken();
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
//message(DTEXT("\tdp = %d\n"), dp);
|
|
||||||
switch (dp)
|
|
||||||
{
|
|
||||||
case DP.end:
|
|
||||||
result = 1;
|
|
||||||
Lret:
|
|
||||||
return result;
|
|
||||||
|
|
||||||
case DP.err:
|
|
||||||
case_error:
|
|
||||||
//message(DTEXT("\terror\n"));
|
|
||||||
default:
|
|
||||||
result = 0;
|
|
||||||
goto Lret;
|
|
||||||
|
|
||||||
case DP.minus:
|
|
||||||
break; // ignore spurious '-'
|
|
||||||
|
|
||||||
case DP.weekday:
|
|
||||||
weekday = number;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DP.month: // month day, [year]
|
|
||||||
month = number;
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp == DP.number)
|
|
||||||
{
|
|
||||||
day = number;
|
|
||||||
sisave = si;
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp == DP.number)
|
|
||||||
{
|
|
||||||
n1 = number;
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp == DP.colon)
|
|
||||||
{ // back up, not a year
|
|
||||||
si = sisave;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ year = n1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case DP.number:
|
|
||||||
n1 = number;
|
|
||||||
dp = nextToken();
|
|
||||||
switch (dp)
|
|
||||||
{
|
|
||||||
case DP.end:
|
|
||||||
year = n1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DP.minus:
|
|
||||||
case DP.slash: // n1/ ? ? ?
|
|
||||||
dp = parseCalendarDate(n1);
|
|
||||||
if (dp == DP.err)
|
|
||||||
goto case_error;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DP.colon: // hh:mm [:ss] [am | pm]
|
|
||||||
dp = parseTimeOfDay(n1);
|
|
||||||
if (dp == DP.err)
|
|
||||||
goto case_error;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DP.ampm:
|
|
||||||
hours = n1;
|
|
||||||
minutes = 0;
|
|
||||||
seconds = 0;
|
|
||||||
ampm = number;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DP.month:
|
|
||||||
day = n1;
|
|
||||||
month = number;
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp == DP.number)
|
|
||||||
{ // day month year
|
|
||||||
year = number;
|
|
||||||
dp = nextToken();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
year = n1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
dp = nextToken();
|
|
||||||
}
|
|
||||||
// @@@ bug in the compiler: this is never reachable
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int parseCalendarDate(int n1)
|
|
||||||
{
|
|
||||||
int n2;
|
|
||||||
int n3;
|
|
||||||
int dp;
|
|
||||||
|
|
||||||
debug(dateparse) printf("DateParse.parseCalendarDate(%d)\n", n1);
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp == DP.month) // day/month
|
|
||||||
{
|
|
||||||
day = n1;
|
|
||||||
month = number;
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp == DP.number)
|
|
||||||
{ // day/month year
|
|
||||||
year = number;
|
|
||||||
dp = nextToken();
|
|
||||||
}
|
|
||||||
else if (dp == DP.minus || dp == DP.slash)
|
|
||||||
{ // day/month/year
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp != DP.number)
|
|
||||||
goto case_error;
|
|
||||||
year = number;
|
|
||||||
dp = nextToken();
|
|
||||||
}
|
|
||||||
return dp;
|
|
||||||
}
|
|
||||||
if (dp != DP.number)
|
|
||||||
goto case_error;
|
|
||||||
n2 = number;
|
|
||||||
//message(DTEXT("\tn2 = %d\n"), n2);
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp == DP.minus || dp == DP.slash)
|
|
||||||
{
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp != DP.number)
|
|
||||||
goto case_error;
|
|
||||||
n3 = number;
|
|
||||||
//message(DTEXT("\tn3 = %d\n"), n3);
|
|
||||||
dp = nextToken();
|
|
||||||
|
|
||||||
// case1: year/month/day
|
|
||||||
// case2: month/day/year
|
|
||||||
int case1, case2;
|
|
||||||
|
|
||||||
case1 = (n1 > 12 ||
|
|
||||||
(n2 >= 1 && n2 <= 12) &&
|
|
||||||
(n3 >= 1 && n3 <= 31));
|
|
||||||
case2 = ((n1 >= 1 && n1 <= 12) &&
|
|
||||||
(n2 >= 1 && n2 <= 31) ||
|
|
||||||
n3 > 31);
|
|
||||||
if (case1 == case2)
|
|
||||||
goto case_error;
|
|
||||||
if (case1)
|
|
||||||
{
|
|
||||||
year = n1;
|
|
||||||
month = n2;
|
|
||||||
day = n3;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
month = n1;
|
|
||||||
day = n2;
|
|
||||||
year = n3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // must be month/day
|
|
||||||
month = n1;
|
|
||||||
day = n2;
|
|
||||||
}
|
|
||||||
return dp;
|
|
||||||
|
|
||||||
case_error:
|
|
||||||
return DP.err;
|
|
||||||
}
|
|
||||||
|
|
||||||
int parseTimeOfDay(int n1)
|
|
||||||
{
|
|
||||||
int dp;
|
|
||||||
int sign;
|
|
||||||
|
|
||||||
// 12am is midnight
|
|
||||||
// 12pm is noon
|
|
||||||
|
|
||||||
//message(DTEXT("DateParse::parseTimeOfDay(%d)\n"), n1);
|
|
||||||
hours = n1;
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp != DP.number)
|
|
||||||
goto case_error;
|
|
||||||
minutes = number;
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp == DP.colon)
|
|
||||||
{
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp != DP.number)
|
|
||||||
goto case_error;
|
|
||||||
seconds = number;
|
|
||||||
dp = nextToken();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
seconds = 0;
|
|
||||||
|
|
||||||
if (dp == DP.ampm)
|
|
||||||
{
|
|
||||||
ampm = number;
|
|
||||||
dp = nextToken();
|
|
||||||
}
|
|
||||||
else if (dp == DP.plus || dp == DP.minus)
|
|
||||||
{
|
|
||||||
Loffset:
|
|
||||||
sign = (dp == DP.minus) ? -1 : 1;
|
|
||||||
dp = nextToken();
|
|
||||||
if (dp != DP.number)
|
|
||||||
goto case_error;
|
|
||||||
tzcorrection = -sign * number;
|
|
||||||
dp = nextToken();
|
|
||||||
}
|
|
||||||
else if (dp == DP.tz)
|
|
||||||
{
|
|
||||||
tzcorrection = number;
|
|
||||||
dp = nextToken();
|
|
||||||
if (number == 0 && (dp == DP.plus || dp == DP.minus))
|
|
||||||
goto Loffset;
|
|
||||||
if (dp == DP.dst)
|
|
||||||
{ tzcorrection += 100;
|
|
||||||
dp = nextToken();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (dp == DP.dsttz)
|
|
||||||
{
|
|
||||||
tzcorrection = number;
|
|
||||||
dp = nextToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
return dp;
|
|
||||||
|
|
||||||
case_error:
|
|
||||||
return DP.err;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
unittest
|
|
||||||
{
|
|
||||||
DateParse dp;
|
|
||||||
Date d;
|
|
||||||
|
|
||||||
dp.parse("March 10, 1959 12:00 -800", d);
|
|
||||||
assert(d.year == 1959);
|
|
||||||
assert(d.month == 3);
|
|
||||||
assert(d.day == 10);
|
|
||||||
assert(d.hour == 12);
|
|
||||||
assert(d.minute == 0);
|
|
||||||
assert(d.second == 0);
|
|
||||||
assert(d.ms == 0);
|
|
||||||
assert(d.weekday == 0);
|
|
||||||
assert(d.tzcorrection == 800);
|
|
||||||
|
|
||||||
dp.parse("Tue Apr 02 02:04:57 GMT-0800 1996", d);
|
|
||||||
assert(d.year == 1996);
|
|
||||||
assert(d.month == 4);
|
|
||||||
assert(d.day == 2);
|
|
||||||
assert(d.hour == 2);
|
|
||||||
assert(d.minute == 4);
|
|
||||||
assert(d.second == 57);
|
|
||||||
assert(d.ms == 0);
|
|
||||||
assert(d.weekday == 3);
|
|
||||||
assert(d.tzcorrection == 800);
|
|
||||||
|
|
||||||
dp.parse("March 14, -1980 21:14:50", d);
|
|
||||||
assert(d.year == 1980);
|
|
||||||
assert(d.month == 3);
|
|
||||||
assert(d.day == 14);
|
|
||||||
assert(d.hour == 21);
|
|
||||||
assert(d.minute == 14);
|
|
||||||
assert(d.second == 50);
|
|
||||||
assert(d.ms == 0);
|
|
||||||
assert(d.weekday == 0);
|
|
||||||
assert(d.tzcorrection == int.min);
|
|
||||||
|
|
||||||
dp.parse("Tue Apr 02 02:04:57 1996", d);
|
|
||||||
assert(d.year == 1996);
|
|
||||||
assert(d.month == 4);
|
|
||||||
assert(d.day == 2);
|
|
||||||
assert(d.hour == 2);
|
|
||||||
assert(d.minute == 4);
|
|
||||||
assert(d.second == 57);
|
|
||||||
assert(d.ms == 0);
|
|
||||||
assert(d.weekday == 3);
|
|
||||||
assert(d.tzcorrection == int.min);
|
|
||||||
|
|
||||||
dp.parse("Tue, 02 Apr 1996 02:04:57 G.M.T.", d);
|
|
||||||
assert(d.year == 1996);
|
|
||||||
assert(d.month == 4);
|
|
||||||
assert(d.day == 2);
|
|
||||||
assert(d.hour == 2);
|
|
||||||
assert(d.minute == 4);
|
|
||||||
assert(d.second == 57);
|
|
||||||
assert(d.ms == 0);
|
|
||||||
assert(d.weekday == 3);
|
|
||||||
assert(d.tzcorrection == 0);
|
|
||||||
|
|
||||||
dp.parse("December 31, 3000", d);
|
|
||||||
assert(d.year == 3000);
|
|
||||||
assert(d.month == 12);
|
|
||||||
assert(d.day == 31);
|
|
||||||
assert(d.hour == 0);
|
|
||||||
assert(d.minute == 0);
|
|
||||||
assert(d.second == 0);
|
|
||||||
assert(d.ms == 0);
|
|
||||||
assert(d.weekday == 0);
|
|
||||||
assert(d.tzcorrection == int.min);
|
|
||||||
|
|
||||||
dp.parse("Wed, 31 Dec 1969 16:00:00 GMT", d);
|
|
||||||
assert(d.year == 1969);
|
|
||||||
assert(d.month == 12);
|
|
||||||
assert(d.day == 31);
|
|
||||||
assert(d.hour == 16);
|
|
||||||
assert(d.minute == 0);
|
|
||||||
assert(d.second == 0);
|
|
||||||
assert(d.ms == 0);
|
|
||||||
assert(d.weekday == 4);
|
|
||||||
assert(d.tzcorrection == 0);
|
|
||||||
|
|
||||||
dp.parse("1/1/1999 12:30 AM", d);
|
|
||||||
assert(d.year == 1999);
|
|
||||||
assert(d.month == 1);
|
|
||||||
assert(d.day == 1);
|
|
||||||
assert(d.hour == 0);
|
|
||||||
assert(d.minute == 30);
|
|
||||||
assert(d.second == 0);
|
|
||||||
assert(d.ms == 0);
|
|
||||||
assert(d.weekday == 0);
|
|
||||||
assert(d.tzcorrection == int.min);
|
|
||||||
|
|
||||||
dp.parse("Tue, 20 May 2003 15:38:58 +0530", d);
|
|
||||||
assert(d.year == 2003);
|
|
||||||
assert(d.month == 5);
|
|
||||||
assert(d.day == 20);
|
|
||||||
assert(d.hour == 15);
|
|
||||||
assert(d.minute == 38);
|
|
||||||
assert(d.second == 58);
|
|
||||||
assert(d.ms == 0);
|
|
||||||
assert(d.weekday == 3);
|
|
||||||
assert(d.tzcorrection == -530);
|
|
||||||
|
|
||||||
debug(dateparse) printf("year = %d, month = %d, day = %d\n%02d:%02d:%02d.%03d\nweekday = %d, tzcorrection = %d\n",
|
|
||||||
d.year, d.month, d.day,
|
|
||||||
d.hour, d.minute, d.second, d.ms,
|
|
||||||
d.weekday, d.tzcorrection);
|
|
||||||
}
|
|
|
@ -31163,61 +31163,6 @@ version(testStdDateTime) unittest
|
||||||
// Section with public helper functions and templates.
|
// Section with public helper functions and templates.
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
/++
|
|
||||||
$(RED Deprecated. It will be removed in March 2012. This is only here to
|
|
||||||
help transition code which uses std.date to using std.datetime.)
|
|
||||||
|
|
||||||
Returns a $(D d_time) for the given $(D SysTime).
|
|
||||||
+/
|
|
||||||
deprecated long sysTimeToDTime(in SysTime sysTime)
|
|
||||||
{
|
|
||||||
return convert!("hnsecs", "msecs")(sysTime.stdTime - 621355968000000000L);
|
|
||||||
}
|
|
||||||
|
|
||||||
version(testStdDateTime) unittest
|
|
||||||
{
|
|
||||||
_assertPred!"=="(sysTimeToDTime(SysTime(DateTime(1970, 1, 1), UTC())),
|
|
||||||
0);
|
|
||||||
_assertPred!"=="(sysTimeToDTime(SysTime(DateTime(1970, 1, 1), FracSec.from!"msecs"(1), UTC())),
|
|
||||||
1);
|
|
||||||
_assertPred!"=="(sysTimeToDTime(SysTime(DateTime(1969, 12, 31, 23, 59, 59), FracSec.from!"msecs"(999), UTC())),
|
|
||||||
-1);
|
|
||||||
|
|
||||||
_assertPred!"=="(sysTimeToDTime(SysTime(DateTime(1970, 1, 2), UTC())),
|
|
||||||
86_400_000);
|
|
||||||
_assertPred!"=="(sysTimeToDTime(SysTime(DateTime(1969, 12, 31), UTC())),
|
|
||||||
-86_400_000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/++
|
|
||||||
$(RED Deprecated. It will be removed in March 2012. This is only here to
|
|
||||||
help transition code which uses std.date to using std.datetime.)
|
|
||||||
|
|
||||||
Returns a $(D SysTime) for the given $(D d_time).
|
|
||||||
+/
|
|
||||||
deprecated SysTime dTimeToSysTime(long dTime, immutable TimeZone tz = null)
|
|
||||||
{
|
|
||||||
immutable hnsecs = convert!("msecs", "hnsecs")(dTime) + 621355968000000000L;
|
|
||||||
|
|
||||||
return SysTime(hnsecs, tz);
|
|
||||||
}
|
|
||||||
|
|
||||||
version(testStdDateTime) unittest
|
|
||||||
{
|
|
||||||
_assertPred!"=="(dTimeToSysTime(0),
|
|
||||||
SysTime(DateTime(1970, 1, 1), UTC()));
|
|
||||||
_assertPred!"=="(dTimeToSysTime(1),
|
|
||||||
SysTime(DateTime(1970, 1, 1), FracSec.from!"msecs"(1), UTC()));
|
|
||||||
_assertPred!"=="(dTimeToSysTime(-1),
|
|
||||||
SysTime(DateTime(1969, 12, 31, 23, 59, 59), FracSec.from!"msecs"(999), UTC()));
|
|
||||||
|
|
||||||
_assertPred!"=="(dTimeToSysTime(86_400_000),
|
|
||||||
SysTime(DateTime(1970, 1, 2), UTC()));
|
|
||||||
_assertPred!"=="(dTimeToSysTime(-86_400_000),
|
|
||||||
SysTime(DateTime(1969, 12, 31), UTC()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/++
|
/++
|
||||||
Whether the given type defines all of the necessary functions for it to
|
Whether the given type defines all of the necessary functions for it to
|
||||||
|
|
422
std/gregorian.d
422
std/gregorian.d
|
@ -1,422 +0,0 @@
|
||||||
// Written in the D programming language.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $(RED Deprecated. It will be removed in March 2012.
|
|
||||||
* Please use std.datetime instead.)
|
|
||||||
|
|
||||||
Macros:
|
|
||||||
WIKI = Phobos/StdGregorian
|
|
||||||
|
|
||||||
Copyright: Copyright Andrei Alexandrescu 2008 - 2009.
|
|
||||||
License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
|
|
||||||
Authors: $(WEB erdani.org, Andrei Alexandrescu)
|
|
||||||
Source: $(PHOBOSSRC std/_gregorian.d)
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
Copyright Andrei Alexandrescu 2010-.
|
|
||||||
Distributed under the Boost Software License, Version 1.0.
|
|
||||||
(See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
module std.gregorian;
|
|
||||||
|
|
||||||
pragma(msg, "Notice: As of Phobos 2.055, std.gregorian has been deprecated. " ~
|
|
||||||
"It will be removed in March 2012. Please use std.datetime instead.");
|
|
||||||
|
|
||||||
version(posix) import core.sys.posix.time;
|
|
||||||
import std.typecons;
|
|
||||||
import std.conv;
|
|
||||||
version(unittest) import std.stdio;
|
|
||||||
|
|
||||||
deprecated:
|
|
||||||
|
|
||||||
version(none) unittest
|
|
||||||
{
|
|
||||||
auto d = Date(2010, May, 1);
|
|
||||||
auto d1 = d;
|
|
||||||
assert(d.year == 2010);
|
|
||||||
assert(d.month == May);
|
|
||||||
assert(d.day == 1);
|
|
||||||
assert(d.dayOfWeek == 6);
|
|
||||||
assert(d.dayOfYear == 121);
|
|
||||||
assert(Date(2010, Jan, 5).dayOfYear == 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
version(none) unittest
|
|
||||||
{
|
|
||||||
auto d1 = Date(negInfin);
|
|
||||||
auto d2 = Date(posInfin);
|
|
||||||
auto d3 = Date(notADateTime);
|
|
||||||
auto d4 = Date(maxDateTime);
|
|
||||||
auto d5 = Date(minDateTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
version(none) unittest
|
|
||||||
{
|
|
||||||
auto d1 = fromString("2002-1-25");
|
|
||||||
auto d2 = fromUndelimitedString("20020125");
|
|
||||||
}
|
|
||||||
|
|
||||||
version(none) unittest
|
|
||||||
{
|
|
||||||
auto d1 = dayClockLocalDay();
|
|
||||||
auto d2 = dayClockUniversalDay();
|
|
||||||
}
|
|
||||||
|
|
||||||
alias ushort GregYear;
|
|
||||||
alias ushort GregMonth;
|
|
||||||
alias ushort GregDay;
|
|
||||||
alias uint GregDayOfWeek;
|
|
||||||
alias uint GregDayOfYear;
|
|
||||||
|
|
||||||
enum { Jan = 1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec }
|
|
||||||
|
|
||||||
// Special constants
|
|
||||||
struct Special { ulong value; }
|
|
||||||
static immutable
|
|
||||||
notADateTime = Special(0),
|
|
||||||
negInfin = Special(1),
|
|
||||||
posInfin = Special(2),
|
|
||||||
minDateTime = Special(3),
|
|
||||||
maxDateTime = Special(4),
|
|
||||||
notSpecial = Special(5);
|
|
||||||
|
|
||||||
struct Date
|
|
||||||
{
|
|
||||||
this(uint year, uint month, uint day)
|
|
||||||
{
|
|
||||||
immutable
|
|
||||||
a = cast(ushort)((14-month)/12),
|
|
||||||
y = cast(ushort)(year + 4800 - a),
|
|
||||||
m = cast(ushort)(month + 12*a - 3);
|
|
||||||
days_ = day + ((153*m + 2)/5) + 365*y + (y/4)
|
|
||||||
- (y/100) + (y/400) - 32045;
|
|
||||||
}
|
|
||||||
|
|
||||||
this(Special s)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Accessors
|
|
||||||
@property GregYear year() const
|
|
||||||
{
|
|
||||||
immutable
|
|
||||||
a = days_ + 32044,
|
|
||||||
b = (4*a + 3)/146097,
|
|
||||||
c = a-((146097*b)/4),
|
|
||||||
d = (4*c + 3)/1461,
|
|
||||||
e = c - (1461*d)/4,
|
|
||||||
m = (5*e + 2)/153;
|
|
||||||
//auto day = cast(ushort) (e - ((153*m + 2)/5) + 1);
|
|
||||||
//auto month = cast(ushort) (m + 3 - 12 * (m/10));
|
|
||||||
immutable year = cast(ushort) (100*b + d - 4800 + (m/10));
|
|
||||||
|
|
||||||
return year;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property GregMonth month() const
|
|
||||||
{
|
|
||||||
immutable
|
|
||||||
a = days_ + 32044,
|
|
||||||
b = (4*a + 3)/146097,
|
|
||||||
c = a-((146097*b)/4),
|
|
||||||
d = (4*c + 3)/1461,
|
|
||||||
e = c - (1461*d)/4,
|
|
||||||
m = (5*e + 2)/153;
|
|
||||||
//auto day = cast(ushort) (e - ((153*m + 2)/5) + 1);
|
|
||||||
immutable month = cast(ushort) (m + 3 - 12 * (m/10));
|
|
||||||
//auto year = cast(ushort) (100*b + d - 4800 + (m/10));
|
|
||||||
|
|
||||||
return month;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property GregDay day() const
|
|
||||||
{
|
|
||||||
immutable
|
|
||||||
a = days_ + 32044,
|
|
||||||
b = (4*a + 3)/146097,
|
|
||||||
c = a-((146097*b)/4),
|
|
||||||
d = (4*c + 3)/1461,
|
|
||||||
e = c - (1461*d)/4,
|
|
||||||
m = (5*e + 2)/153,
|
|
||||||
day = cast(ushort) (e - ((153*m + 2)/5) + 1);
|
|
||||||
//auto month = cast(ushort) (m + 3 - 12 * (m/10));
|
|
||||||
//auto year = cast(ushort) (100*b + d - 4800 + (m/10));
|
|
||||||
|
|
||||||
return day;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property Tuple!(GregYear, GregMonth, GregDay)
|
|
||||||
yearMonthDay() const
|
|
||||||
{
|
|
||||||
immutable
|
|
||||||
a = days_ + 32044,
|
|
||||||
b = (4*a + 3)/146097,
|
|
||||||
c = a-((146097*b)/4),
|
|
||||||
d = (4*c + 3)/1461,
|
|
||||||
e = c - (1461*d)/4,
|
|
||||||
m = (5*e + 2)/153;
|
|
||||||
auto day = cast(ushort) (e - ((153*m + 2)/5) + 1);
|
|
||||||
auto month = cast(ushort) (m + 3 - 12 * (m/10));
|
|
||||||
auto year = cast(ushort) (100*b + d - 4800 + (m/10));
|
|
||||||
|
|
||||||
return tuple(year, month, day);
|
|
||||||
}
|
|
||||||
|
|
||||||
@property GregDayOfWeek dayOfWeek() const
|
|
||||||
{
|
|
||||||
immutable
|
|
||||||
ymd = yearMonthDay,
|
|
||||||
a = cast(ushort) ((14-ymd._1)/12),
|
|
||||||
y = cast(ushort) (ymd._0 - a),
|
|
||||||
m = cast(ushort) (ymd._1 + 12*a - 2),
|
|
||||||
d = cast(ushort) ((ymd._2 + y + (y/4) - (y/100) +
|
|
||||||
(y/400) + (31*m)/12) % 7);
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property GregDayOfYear dayOfYear() const
|
|
||||||
{
|
|
||||||
const start_of_year = Date(year(), 1, 1);
|
|
||||||
auto doy = cast(ushort) ((this - start_of_year).days() + 1);
|
|
||||||
return cast(GregDayOfYear) doy;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property Date endOfMonth() const
|
|
||||||
{
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@property bool isInfinity() const
|
|
||||||
{
|
|
||||||
return isNegInfinity || isPosInfinity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property bool isNegInfinity() const
|
|
||||||
{
|
|
||||||
return days_ == negInfin.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property bool isPosInfinity() const
|
|
||||||
{
|
|
||||||
return days_ == posInfin.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property bool isNotADate() const
|
|
||||||
{
|
|
||||||
return days_ == notADateTime.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property bool isSpecial() const
|
|
||||||
{
|
|
||||||
return isNotADate || isInfinity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property Special asSpecial() const
|
|
||||||
{
|
|
||||||
return days_ < notSpecial.value
|
|
||||||
? Special(days_)
|
|
||||||
: notSpecial;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property long modJulianDay() const
|
|
||||||
{
|
|
||||||
auto ymd = yearMonthDay();
|
|
||||||
return julianDay(ymd) - 2400001; //prerounded
|
|
||||||
}
|
|
||||||
|
|
||||||
static @property long julianDay(Tuple!(ushort, ushort, ushort) ymd)
|
|
||||||
{
|
|
||||||
immutable
|
|
||||||
a = cast(ushort) ((14-ymd._1)/12),
|
|
||||||
y = cast(ushort) (ymd._0 + 4800 - a),
|
|
||||||
m = cast(ushort) (ymd._1 + 12*a - 3),
|
|
||||||
d = ymd._2 + ((153*m + 2)/5) + 365*y + (y/4) - (y/100)
|
|
||||||
+ (y/400) - 32045;
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isLeapYear(uint year)
|
|
||||||
{
|
|
||||||
//divisible by 4, not if divisible by 100, but true if
|
|
||||||
//divisible by 400
|
|
||||||
return (!(year % 4)) && ((year % 100) || (!(year % 400)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@property int weekNumber() const
|
|
||||||
{
|
|
||||||
auto
|
|
||||||
ymd = yearMonthDay,
|
|
||||||
julianbegin = julianDay(tuple(cast(ushort)ymd._0,
|
|
||||||
cast(ushort)1, cast(ushort)1)),
|
|
||||||
juliantoday = julianDay(ymd);
|
|
||||||
long day = (julianbegin + 3) % 7;
|
|
||||||
ulong week = (juliantoday + day - julianbegin + 4)/7;
|
|
||||||
|
|
||||||
if ((week >= 1) && (week <= 52))
|
|
||||||
{
|
|
||||||
return cast(int) week;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((week == 53))
|
|
||||||
{
|
|
||||||
if((day==6) ||(day == 5 && isLeapYear(ymd._0)))
|
|
||||||
{
|
|
||||||
return cast(int) week; //under these circumstances week == 53.
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 1; //monday - wednesday is in week 1 of next year
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//if the week is not in current year recalculate using the
|
|
||||||
//previous year as the beginning year
|
|
||||||
else
|
|
||||||
if (week == 0)
|
|
||||||
{
|
|
||||||
julianbegin = julianDay(
|
|
||||||
tuple(cast(ushort) (ymd._0 - 1), cast(ushort) 1,
|
|
||||||
cast(ushort) 1));
|
|
||||||
juliantoday = julianDay(ymd);
|
|
||||||
day = (julianbegin + 3) % 7;
|
|
||||||
week = (juliantoday + day - julianbegin + 4)/7;
|
|
||||||
return cast(int) week;
|
|
||||||
}
|
|
||||||
return cast(int) week; //not reachable -- well except if day == 5 and
|
|
||||||
//is_leap_year != true
|
|
||||||
}
|
|
||||||
|
|
||||||
@property uint endOfMonthDay() const
|
|
||||||
{
|
|
||||||
switch (month) {
|
|
||||||
case 2:
|
|
||||||
if (isLeapYear(year)) {
|
|
||||||
return 29;
|
|
||||||
} else {
|
|
||||||
return 28;
|
|
||||||
}
|
|
||||||
case 4:
|
|
||||||
case 6:
|
|
||||||
case 9:
|
|
||||||
case 11:
|
|
||||||
return 30;
|
|
||||||
default:
|
|
||||||
return 31;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@property string toSimpleString() const
|
|
||||||
{
|
|
||||||
auto ymd = yearMonthDay;
|
|
||||||
return text(ymd._0, '-', ymd._1, '-', ymd._2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@property string toIsoString() const
|
|
||||||
{
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@property string toIsoExtendedString() const
|
|
||||||
{
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool opEquals(ref const Date rhs) const
|
|
||||||
{
|
|
||||||
return days_ == rhs.days_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int opCmp(in Date rhs) const
|
|
||||||
{
|
|
||||||
return days_ < rhs.days_ ? -1 : days_ > rhs.days_ ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Date opBinary(string op)(const Date d) const
|
|
||||||
// if (op == "-")
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
Days opBinary(string op)(const Date d) const
|
|
||||||
if (op == "-")
|
|
||||||
{
|
|
||||||
if (!isSpecial && !d.isSpecial)
|
|
||||||
{
|
|
||||||
return Days(days_ - d.days_);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static if (is(tm))
|
|
||||||
{
|
|
||||||
tm toTm()
|
|
||||||
{
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ulong days_;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Days
|
|
||||||
{
|
|
||||||
private long days_;
|
|
||||||
this(long d) { days_ = d; }
|
|
||||||
this(Special s) { }
|
|
||||||
@property long days() const { return days_; }
|
|
||||||
@property bool isNegative() const { return days_ < 0; }
|
|
||||||
@property static Days unit() { return Days(1); }
|
|
||||||
@property bool isSpecial()
|
|
||||||
{
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
bool opEquals(ref const Days rhs) const
|
|
||||||
{
|
|
||||||
return days_ == rhs.days_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int opCmp(in Days rhs) const
|
|
||||||
{
|
|
||||||
return days_ < rhs.days_ ? -1 : days_ > rhs.days_ ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Days opBinary(string op)(Days d) const
|
|
||||||
if (op == "+" || op == "-")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Date fromString(in char[] s)
|
|
||||||
{
|
|
||||||
Date result;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Date fromUndelimitedString(in char[] s)
|
|
||||||
{
|
|
||||||
Date result;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Date dayClockLocalDay()
|
|
||||||
{
|
|
||||||
Date result;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Date dayClockUniversalDay()
|
|
||||||
{
|
|
||||||
Date result;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static if (is(tm))
|
|
||||||
{
|
|
||||||
Date dateFromTm(tm)
|
|
||||||
{
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,8 +22,7 @@ public import std.conv;
|
||||||
public import std.cpuid;
|
public import std.cpuid;
|
||||||
public import std.cstream;
|
public import std.cstream;
|
||||||
public import std.ctype;
|
public import std.ctype;
|
||||||
public import std.date;
|
public import std.datetime;
|
||||||
public import std.dateparse;
|
|
||||||
public import std.demangle;
|
public import std.demangle;
|
||||||
public import std.file;
|
public import std.file;
|
||||||
public import std.format;
|
public import std.format;
|
||||||
|
@ -79,7 +78,7 @@ version (all)
|
||||||
int a[];
|
int a[];
|
||||||
a.reverse; // adi
|
a.reverse; // adi
|
||||||
a.sort; // qsort
|
a.sort; // qsort
|
||||||
std.date.getUTCtime(); // date
|
Clock.currTime(); // datetime
|
||||||
Exception e = new ReadException(""); // stream
|
Exception e = new ReadException(""); // stream
|
||||||
din.eof(); // cstream
|
din.eof(); // cstream
|
||||||
isValidDchar(cast(dchar)0); // utf
|
isValidDchar(cast(dchar)0); // utf
|
||||||
|
|
26
win32.mak
26
win32.mak
|
@ -109,7 +109,7 @@ SRCS_12 = std\array.d std\functional.d std\range.d \
|
||||||
std\path.d std\outbuffer.d std\utf.d
|
std\path.d std\outbuffer.d std\utf.d
|
||||||
|
|
||||||
SRCS_2 = std\csv.d std\math.d std\complex.d std\numeric.d std\bigint.d \
|
SRCS_2 = std\csv.d std\math.d std\complex.d std\numeric.d std\bigint.d \
|
||||||
std\dateparse.d std\date.d std\datetime.d \
|
std\datetime.d \
|
||||||
std\metastrings.d std\bitmanip.d std\typecons.d \
|
std\metastrings.d std\bitmanip.d std\typecons.d \
|
||||||
std\uni.d std\base64.d std\md5.d std\ctype.d std\ascii.d \
|
std\uni.d std\base64.d std\md5.d std\ctype.d std\ascii.d \
|
||||||
std\demangle.d std\uri.d std\mmfile.d std\getopt.d \
|
std\demangle.d std\uri.d std\mmfile.d std\getopt.d \
|
||||||
|
@ -126,13 +126,11 @@ SRCS_3 = std\variant.d \
|
||||||
std\stream.d std\socket.d std\socketstream.d \
|
std\stream.d std\socket.d std\socketstream.d \
|
||||||
std\perf.d std\container.d std\conv.d \
|
std\perf.d std\container.d std\conv.d \
|
||||||
std\zip.d std\cstream.d std\loader.d \
|
std\zip.d std\cstream.d std\loader.d \
|
||||||
std\datebase.d \
|
|
||||||
std\regex.d \
|
std\regex.d \
|
||||||
std\stdarg.d \
|
std\stdarg.d \
|
||||||
std\stdint.d \
|
std\stdint.d \
|
||||||
std\json.d \
|
std\json.d \
|
||||||
std\parallelism.d \
|
std\parallelism.d \
|
||||||
std\gregorian.d \
|
|
||||||
std\mathspecial.d \
|
std\mathspecial.d \
|
||||||
std\internal\math\biguintcore.d \
|
std\internal\math\biguintcore.d \
|
||||||
std\internal\math\biguintnoasm.d std\internal\math\biguintx86.d \
|
std\internal\math\biguintnoasm.d std\internal\math\biguintx86.d \
|
||||||
|
@ -195,7 +193,6 @@ DOCS= $(DOC)\object.html \
|
||||||
$(DOC)\std_cstream.html \
|
$(DOC)\std_cstream.html \
|
||||||
$(DOC)\std_ctype.html \
|
$(DOC)\std_ctype.html \
|
||||||
$(DOC)\std_csv.html \
|
$(DOC)\std_csv.html \
|
||||||
$(DOC)\std_date.html \
|
|
||||||
$(DOC)\std_datetime.html \
|
$(DOC)\std_datetime.html \
|
||||||
$(DOC)\std_demangle.html \
|
$(DOC)\std_demangle.html \
|
||||||
$(DOC)\std_encoding.html \
|
$(DOC)\std_encoding.html \
|
||||||
|
@ -205,7 +202,6 @@ DOCS= $(DOC)\object.html \
|
||||||
$(DOC)\std_functional.html \
|
$(DOC)\std_functional.html \
|
||||||
$(DOC)\std_gc.html \
|
$(DOC)\std_gc.html \
|
||||||
$(DOC)\std_getopt.html \
|
$(DOC)\std_getopt.html \
|
||||||
$(DOC)\std_gregorian.html \
|
|
||||||
$(DOC)\std_json.html \
|
$(DOC)\std_json.html \
|
||||||
$(DOC)\std_math.html \
|
$(DOC)\std_math.html \
|
||||||
$(DOC)\std_mathspecial.html \
|
$(DOC)\std_mathspecial.html \
|
||||||
|
@ -263,10 +259,10 @@ DOCS= $(DOC)\object.html \
|
||||||
SRC= unittest.d crc32.d index.d
|
SRC= unittest.d crc32.d index.d
|
||||||
|
|
||||||
SRC_STD= std\zlib.d std\zip.d std\stdint.d std\container.d std\conv.d std\utf.d std\uri.d \
|
SRC_STD= std\zlib.d std\zip.d std\stdint.d std\container.d std\conv.d std\utf.d std\uri.d \
|
||||||
std\math.d std\string.d std\path.d std\date.d std\datetime.d \
|
std\math.d std\string.d std\path.d std\datetime.d \
|
||||||
std\ctype.d std\csv.d std\file.d std\compiler.d std\system.d \
|
std\ctype.d std\csv.d std\file.d std\compiler.d std\system.d \
|
||||||
std\outbuffer.d std\md5.d std\base64.d \
|
std\outbuffer.d std\md5.d std\base64.d \
|
||||||
std\dateparse.d std\mmfile.d \
|
std\mmfile.d \
|
||||||
std\syserror.d \
|
std\syserror.d \
|
||||||
std\regexp.d std\random.d std\stream.d std\process.d \
|
std\regexp.d std\random.d std\stream.d std\process.d \
|
||||||
std\socket.d std\socketstream.d std\loader.d std\stdarg.d std\format.d \
|
std\socket.d std\socketstream.d std\loader.d std\stdarg.d std\format.d \
|
||||||
|
@ -278,8 +274,8 @@ SRC_STD= std\zlib.d std\zip.d std\stdint.d std\container.d std\conv.d std\utf.d
|
||||||
std\functional.d std\algorithm.d std\array.d std\typecons.d \
|
std\functional.d std\algorithm.d std\array.d std\typecons.d \
|
||||||
std\json.d std\xml.d std\encoding.d std\bigint.d std\concurrency.d \
|
std\json.d std\xml.d std\encoding.d std\bigint.d std\concurrency.d \
|
||||||
std\range.d std\stdiobase.d std\parallelism.d \
|
std\range.d std\stdiobase.d std\parallelism.d \
|
||||||
std\regex.d std\datebase.d \
|
std\regex.d \
|
||||||
std\gregorian.d std\exception.d std\ascii.d
|
std\exception.d std\ascii.d
|
||||||
|
|
||||||
SRC_STD_NET= std\net\isemail.d std\net\curl.d
|
SRC_STD_NET= std\net\isemail.d std\net\curl.d
|
||||||
|
|
||||||
|
@ -433,12 +429,6 @@ ctype.obj : std\ctype.d
|
||||||
csv.obj : std\csv.d
|
csv.obj : std\csv.d
|
||||||
$(DMD) -c $(DFLAGS) std\csv.d
|
$(DMD) -c $(DFLAGS) std\csv.d
|
||||||
|
|
||||||
date.obj : std\dateparse.d std\date.d
|
|
||||||
$(DMD) -c $(DFLAGS) std\date.d
|
|
||||||
|
|
||||||
dateparse.obj : std\dateparse.d std\date.d
|
|
||||||
$(DMD) -c $(DFLAGS) std\dateparse.d
|
|
||||||
|
|
||||||
datetime.obj : std\datetime.d
|
datetime.obj : std\datetime.d
|
||||||
$(DMD) -c $(DFLAGS) std\datetime.d
|
$(DMD) -c $(DFLAGS) std\datetime.d
|
||||||
|
|
||||||
|
@ -746,9 +736,6 @@ $(DOC)\std_ctype.html : $(STDDOC) std\ctype.d
|
||||||
$(DOC)\std_csv.html : $(STDDOC) std\csv.d
|
$(DOC)\std_csv.html : $(STDDOC) std\csv.d
|
||||||
$(DMD) -c -o- $(DFLAGS) -Df$(DOC)\std_csv.html $(STDDOC) std\csv.d
|
$(DMD) -c -o- $(DFLAGS) -Df$(DOC)\std_csv.html $(STDDOC) std\csv.d
|
||||||
|
|
||||||
$(DOC)\std_date.html : $(STDDOC) std\date.d
|
|
||||||
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_date.html $(STDDOC) std\date.d
|
|
||||||
|
|
||||||
$(DOC)\std_datetime.html : $(STDDOC) std\datetime.d
|
$(DOC)\std_datetime.html : $(STDDOC) std\datetime.d
|
||||||
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_datetime.html $(STDDOC) std\datetime.d
|
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_datetime.html $(STDDOC) std\datetime.d
|
||||||
|
|
||||||
|
@ -773,9 +760,6 @@ $(DOC)\std_gc.html : $(STDDOC) $(DRUNTIME)\src\core\memory.d
|
||||||
$(DOC)\std_getopt.html : $(STDDOC) std\getopt.d
|
$(DOC)\std_getopt.html : $(STDDOC) std\getopt.d
|
||||||
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_getopt.html $(STDDOC) std\getopt.d
|
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_getopt.html $(STDDOC) std\getopt.d
|
||||||
|
|
||||||
$(DOC)\std_gregorian.html : $(STDDOC) std\gregorian.d
|
|
||||||
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_gregorian.html $(STDDOC) std\gregorian.d
|
|
||||||
|
|
||||||
$(DOC)\std_json.html : $(STDDOC) std\json.d
|
$(DOC)\std_json.html : $(STDDOC) std\json.d
|
||||||
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_json.html $(STDDOC) std\json.d
|
$(DMD) -c -o- $(DDOCFLAGS) -Df$(DOC)\std_json.html $(STDDOC) std\json.d
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue