@@ -1914,10 +1914,11 @@ struct YearQuarter
1914
1914
1915
1915
Year 0 is a leap year.
1916
1916
+/
1917
- extern (C++ , " boost" , " gregorian" )
1918
- extern (C++ , class)
1917
+ // extern(C++, "boost", "gregorian")
1918
+ // extern(C++, class)
1919
+ extern (C++ , " mir" )
1919
1920
@serdeProxy! YearMonthDay
1920
- struct date
1921
+ struct Date
1921
1922
{
1922
1923
extern (D ):
1923
1924
public :
@@ -1927,7 +1928,7 @@ public:
1927
1928
// /
1928
1929
uint toHash () @safe pure nothrow @nogc const scope
1929
1930
{
1930
- return _julianDay ;
1931
+ return _dayNumber ;
1931
1932
}
1932
1933
1933
1934
/+ +
@@ -1957,7 +1958,7 @@ public:
1957
1958
{
1958
1959
if (_year == 1 )
1959
1960
{
1960
- ret._julianDay = dayOfYear;
1961
+ ret._dayNumber = dayOfYear;
1961
1962
goto R;
1962
1963
}
1963
1964
@@ -1975,11 +1976,11 @@ public:
1975
1976
1976
1977
days += dayOfYear;
1977
1978
1978
- ret._julianDay = days;
1979
+ ret._dayNumber = days;
1979
1980
}
1980
1981
else if (_year == 0 )
1981
1982
{
1982
- ret._julianDay = dayOfYear - daysInLeapYear;
1983
+ ret._dayNumber = dayOfYear - daysInLeapYear;
1983
1984
}
1984
1985
else
1985
1986
{
@@ -2005,10 +2006,10 @@ public:
2005
2006
else
2006
2007
days -= daysInLeapYear - dayOfYear;
2007
2008
2008
- ret._julianDay = days;
2009
+ ret._dayNumber = days;
2009
2010
}
2010
2011
R:
2011
- ret._julianDay += _julianShift ;
2012
+ ret._dayNumber -= 1 ;
2012
2013
return ret;
2013
2014
}
2014
2015
@@ -2073,7 +2074,7 @@ public:
2073
2074
version (mir_test)
2074
2075
@safe unittest
2075
2076
{
2076
- auto d = date (YearMonthDay(2020 , Month.may, 31 ));
2077
+ auto d = Date (YearMonthDay(2020 , Month.may, 31 ));
2077
2078
}
2078
2079
2079
2080
version (D_Exceptions)
@@ -2094,8 +2095,8 @@ public:
2094
2095
version (mir_test)
2095
2096
@safe unittest
2096
2097
{
2097
- auto d1 = date (YearQuarter(2020 , Quarter.q2));
2098
- auto d2 = date (YearQuarter(2020 , Quarter.q2), AssumePeriod.end);
2098
+ auto d1 = Date (YearQuarter(2020 , Quarter.q2));
2099
+ auto d2 = Date (YearQuarter(2020 , Quarter.q2), AssumePeriod.end);
2099
2100
}
2100
2101
2101
2102
version (D_Exceptions)
@@ -2109,8 +2110,8 @@ public:
2109
2110
version (mir_test)
2110
2111
@safe unittest
2111
2112
{
2112
- auto d1 = date (YearMonth(2020 , Month.may));
2113
- auto d2 = date (YearMonth(2020 , Month.may), AssumePeriod.end);
2113
+ auto d1 = Date (YearMonth(2020 , Month.may));
2114
+ auto d2 = Date (YearMonth(2020 , Month.may), AssumePeriod.end);
2114
2115
}
2115
2116
2116
2117
version (D_Exceptions)
@@ -2190,9 +2191,10 @@ public:
2190
2191
Params:
2191
2192
day = Julian day.
2192
2193
+/
2194
+ deprecated (" Use `fromDayNumber` adjusted by -1_721_426" )
2193
2195
this (int day) @safe pure nothrow @nogc
2194
2196
{
2195
- _julianDay = day;
2197
+ _dayNumber = day - ( 1 + _julianShift) ;
2196
2198
}
2197
2199
2198
2200
version (mir_test)
@@ -2218,7 +2220,7 @@ public:
2218
2220
+/
2219
2221
int opCmp (Date rhs) const @safe pure nothrow @nogc
2220
2222
{
2221
- return this ._julianDay - rhs._julianDay ;
2223
+ return this ._dayNumber - rhs._dayNumber ;
2222
2224
}
2223
2225
2224
2226
version (mir_test)
@@ -2310,7 +2312,7 @@ public:
2310
2312
+/
2311
2313
@property DayOfWeek dayOfWeek() const @safe pure nothrow @nogc
2312
2314
{
2313
- return getDayOfWeek (_julianDay );
2315
+ return getDayOfWeek (_dayNumber );
2314
2316
}
2315
2317
2316
2318
version (mir_test)
@@ -2324,12 +2326,23 @@ public:
2324
2326
static assert (! __traits(compiles, idate.dayOfWeek = DayOfWeek.sun));
2325
2327
}
2326
2328
2329
+ /+ +
2330
+ Params:
2331
+ dayNumber = Day Of Gregorian Calendar Minus One
2332
+ +/
2333
+ static Date fromDayNumber (int dayNumber) @safe pure nothrow @nogc
2334
+ {
2335
+ Date date;
2336
+ date._dayNumber = dayNumber;
2337
+ return date;
2338
+ }
2339
+
2327
2340
/+ +
2328
2341
The Xth day of the Gregorian Calendar that this $(LREF Date) is on.
2329
2342
+/
2330
2343
@property int dayOfGregorianCal() const @safe pure nothrow @nogc
2331
2344
{
2332
- return _julianDay - _julianShift ;
2345
+ return _dayNumber + 1 ;
2333
2346
}
2334
2347
2335
2348
// /
@@ -2369,18 +2382,21 @@ public:
2369
2382
2370
2383
Params:
2371
2384
day = The day of the Gregorian Calendar to set this $(LREF Date) to.
2385
+
2386
+ Note:
2387
+ Zero value corresponds to
2372
2388
+/
2373
2389
@property void dayOfGregorianCal(int day) @safe pure nothrow @nogc
2374
2390
{
2375
- this = Date ( day + _julianShift) ;
2391
+ _dayNumber = day - 1 ;
2376
2392
}
2377
2393
2378
2394
// /
2379
2395
version (mir_test)
2380
2396
@safe unittest
2381
2397
{
2398
+ import mir.test;
2382
2399
auto date = Date .init;
2383
- date.dayOfGregorianCal = 1 ;
2384
2400
assert (date == Date (1 , 1 , 1 ));
2385
2401
2386
2402
date.dayOfGregorianCal = 365 ;
@@ -2417,20 +2433,20 @@ public:
2417
2433
static assert (! __traits(compiles, idate.dayOfGregorianCal = 187 ));
2418
2434
}
2419
2435
2420
- private enum uint _startDict = Date (1900 , 1 , 1 )._julianDay ; // [
2421
- private enum uint _endDict = Date (2040 , 1 , 1 )._julianDay ; // )
2436
+ private enum uint _startDict = Date (1900 , 1 , 1 )._dayNumber ; // [
2437
+ private enum uint _endDict = Date (2040 , 1 , 1 )._dayNumber ; // )
2422
2438
static immutable _dictYMD = ()
2423
2439
{
2424
2440
YearMonthDay[Date ._endDict - Date ._startDict] dict;
2425
2441
foreach (uint i; 0 .. dict.length)
2426
- dict[i] = Date (i + Date ._startDict).yearMonthDayImpl;
2442
+ dict[i] = Date .fromDayNumber (i + Date ._startDict).yearMonthDayImpl;
2427
2443
return dict;
2428
2444
}();
2429
2445
2430
2446
// /
2431
2447
YearMonthDay yearMonthDay () const @safe pure nothrow @nogc @property
2432
2448
{
2433
- uint day = _julianDay ;
2449
+ uint day = _dayNumber ;
2434
2450
if (day < _endDict)
2435
2451
{
2436
2452
import mir.checkedint: subu;
@@ -2445,7 +2461,7 @@ public:
2445
2461
// /
2446
2462
YearQuarter yearQuarter () const @safe pure nothrow @nogc @property
2447
2463
{
2448
- uint day = _julianDay ;
2464
+ uint day = _dayNumber ;
2449
2465
if (day < _endDict)
2450
2466
{
2451
2467
return yearMonthDay ().YearQuarter;
@@ -2748,7 +2764,7 @@ public:
2748
2764
version (mir_test)
2749
2765
@safe unittest
2750
2766
{
2751
- auto d = date (2020 , Month.may, 31 );
2767
+ auto d = Date (2020 , Month.may, 31 );
2752
2768
auto yq = d.yearQuarterImpl;
2753
2769
}
2754
2770
@@ -2759,7 +2775,7 @@ public:
2759
2775
{
2760
2776
with (yearMonthDay)
2761
2777
{
2762
- int d = _julianDay - day;
2778
+ int d = _dayNumber - day;
2763
2779
final switch (month) with (Month)
2764
2780
{
2765
2781
case jan: d += maxDay(year, jan); goto case ;
@@ -2778,7 +2794,7 @@ public:
2778
2794
case nov: d += maxDay(year, nov); goto case ;
2779
2795
case dec: d += maxDay(year, dec); break ;
2780
2796
}
2781
- return Date (d);
2797
+ return Date .fromDayNumber (d);
2782
2798
}
2783
2799
}
2784
2800
@@ -2798,7 +2814,7 @@ public:
2798
2814
@property Date endOfMonth() const @safe pure nothrow @nogc
2799
2815
{
2800
2816
with (yearMonthDay)
2801
- return Date (_julianDay + maxDay(year, month) - day);
2817
+ return Date .fromDayNumber(_dayNumber + maxDay(year, month) - day);
2802
2818
}
2803
2819
2804
2820
// /
@@ -2853,25 +2869,25 @@ public:
2853
2869
// /
2854
2870
int opBinary (string op : " -" )(Date rhs) const
2855
2871
{
2856
- return _julianDay - rhs._julianDay ;
2872
+ return _dayNumber - rhs._dayNumber ;
2857
2873
}
2858
2874
2859
2875
// /
2860
2876
Date opBinary (string op : " +" )(int rhs) const
2861
2877
{
2862
- return Date (_julianDay + rhs);
2878
+ return Date .fromDayNumber(_dayNumber + rhs);
2863
2879
}
2864
2880
2865
2881
// /
2866
2882
Date opBinaryRight (string op : " +" )(int rhs) const
2867
2883
{
2868
- return Date (_julianDay + rhs);
2884
+ return Date .fromDayNumber(_dayNumber + rhs);
2869
2885
}
2870
2886
2871
2887
// /
2872
2888
Date opBinary (string op : " -" )(int rhs) const
2873
2889
{
2874
- return Date (_julianDay - rhs);
2890
+ return Date .fromDayNumber(_dayNumber - rhs);
2875
2891
}
2876
2892
2877
2893
// /
@@ -2943,7 +2959,7 @@ public:
2943
2959
+/
2944
2960
@property int julianDay() const @safe pure nothrow @nogc
2945
2961
{
2946
- return _julianDay ;
2962
+ return _dayNumber + ( 1 + _julianShift) ;
2947
2963
}
2948
2964
2949
2965
version (mir_test)
@@ -3716,7 +3732,7 @@ public:
3716
3732
+/
3717
3733
@property static Date min() @safe pure nothrow @nogc
3718
3734
{
3719
- return Date ( - ( int .max / 2 ) );
3735
+ return Date .fromDayNumber( int .max);
3720
3736
}
3721
3737
3722
3738
/+ +
@@ -3725,7 +3741,7 @@ public:
3725
3741
+/
3726
3742
@property static Date max() @safe pure nothrow @nogc
3727
3743
{
3728
- return Date (int .max / 2 );
3744
+ return Date .fromDayNumber (int .min );
3729
3745
}
3730
3746
3731
3747
private :
@@ -3766,7 +3782,7 @@ package:
3766
3782
+/
3767
3783
ref Date _addDays (long days) return @safe pure nothrow @nogc
3768
3784
{
3769
- _julianDay = cast (int )(_julianDay + days);
3785
+ _dayNumber = cast (int )(_dayNumber + days);
3770
3786
return this ;
3771
3787
}
3772
3788
@@ -3929,11 +3945,12 @@ package:
3929
3945
static assert (! __traits(compiles, idate._addDays(12 )));
3930
3946
}
3931
3947
3932
- int _julianDay ;
3948
+ int _dayNumber ;
3933
3949
}
3934
3950
3935
3951
// / ditto
3936
- alias Date = date;
3952
+ deprecated (" use `Date` instead" )
3953
+ alias date = Date ;
3937
3954
3938
3955
/+ +
3939
3956
Returns the number of days from the current day of the week to the given
0 commit comments