datetime

Module contains Date/Time functionality.

See Also:
ISO 8601

License:
Boost License 1.0.

Authors:
Jonathan M Davis

Copyright Jonathan M Davis 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



alias Year;
Unit for holding a Gregorian year.

alias MonthOfYear;
Unit for holding a Gregorian month

alias DayOfMonth;
Unit for holding the day of a Gregorian month.

alias DayOfYear;
Unit for holding the day of a Gregorian year.

alias DayOfGregorianCal;
Unit for holding Xth day of the Gregorian Calendar.

alias ISOWeek;
Unit for holding the ISOWeek of a Gregorian year.

alias Hour;
Unit for holding the hour of the day.

alias Minute;
Unit for holding the minute of the hour.

alias Second;
Unit for holding second of the minute.

alias Millisecond;
Unit for holding milliseconds of a second.

alias Microsecond;
Unit for holding microseconds of a second.

alias Tick;
Unit for holding 100 nanoseconds.

enum DayOfWeek;
Represents the 7 days of the Gregorian month.

enum TimeUnit;
Represents possible units of time.

enum AllowDayOverflow;
In some Date calculations, adding months or years can cause the Date to fall on a day of the month which is not valid (e.g. February 29th 2001 or June 31st 2000). If overlflow is allowed (as is the default), then the month will be incremented accordingly (so, February 29th 2001 would become March 1st 2001, and June 31st 2000 would become July 1st 2000). If overlow is not allowed, then the day will be adjusted to the last valid day in that month (so, February 29th 2001 becomes February 28th 2001 and June 31st 2000 becomes June 30th 2000).

AllowDayOverflow only applies to calculations involving months or years. Adding any smaller units (such as days) would just add the appropriate amount and adjust the month and year accordingly.

class TimeUnitConv;
Effectively a namespace to better organize time conversion functions. Its functions relate to converting between the different TimeUnits.

long to(TimeUnit tu1, TimeUnit tu2)(long value);
Generic way of converting between two time units. Conversions to smaller unites use truncating division.

Params:
tu1 The units of time to covert from.
tu1 The units of time to covert type.
value The value to convert.

Examples:
        assert(to!(TimeUnit.year, TimeUnit.month)(1) == 12);
        assert(to!(TimeUnit.month, TimeUnit.year)(12) == 1);


long to(TimeUnit tu1, TimeUnit tu2)(long value);
Generic way of converting between two time units. Conversions to smaller unites use truncating division.

Params:
tu1 The units of time to covert from.
tu1 The units of time to covert type.
value The value to convert.

Examples:
        assert(to!(TimeUnit.week, TimeUnit.day)(1) == 7);
        assert(to!(TimeUnit.hour, TimeUnit.second)(1) == 3600);
        assert(to!(TimeUnit.second, TimeUnit.day)(1) == 0);
        assert(to!(TimeUnit.second, TimeUnit.day)(86_400) == 1);


static long yearsToMonths(long years);
Convert from TimeUnit.year to TimeUnit.month.

static long monthsToYears(long months);
Convert from TimeUnit.month to TimeUnit.month. Uses truncating division.

static long weeksToTicks(long weeks);
Convert from TimeUnit.week to TimeUnit.tick.

Params:
value The number of weeks to convert to ticks.

static long daysToTicks(long days);
Convert from TimeUnit.day to TimeUnit.tick.

Params:
value The number of days to convert to ticks.

static long hoursToTicks(long hours);
Convert from TimeUnit.hour to TimeUnit.tick.

Params:
value The number of hours to convert to ticks.

static long minToTicks(long minutes);
Convert from TimeUnit.minute to TimeUnit.tick.

Params:
value The number of minutes to convert to ticks.

static long secToTicks(long seconds);
Convert from TimeUnit.second to TimeUnit.tick.

Params:
value The number of seconds to convert to ticks.

static long msToTicks(long ms);
Convert from TimeUnit.millisecond to TimeUnit.tick.

Params:
value The number of milliseconds to convert to ticks.

static long usToTicks(long us);
Convert from TimeUnit.microsecond to TimeUnit.tick.

Params:
value The number of microseconds to convert to ticks.

static long ticksToWeeks(long ticks);
Convert from TimeUnit.tick to TimeUnit.week. Uses truncating division.

Params:
value The number of ticks to convert to weeks.

static long ticksToDays(long ticks);
Convert from TimeUnit.tick to TimeUnit.day. Uses truncating division.

Params:
value The number of ticks to convert to days.

static long ticksToHours(long ticks);
Convert from TimeUnit.tick to TimeUnit.hour. Uses truncating division.

Params:
value The number of ticks to convert to hours.

static long ticksToMin(long ticks);
Convert from TimeUnit.tick to TimeUnit.minute. Uses truncating division.

Params:
value The number of ticks to convert to minutes.

static long ticksToSec(long ticks);
Convert from TimeUnit.tick to TimeUnit.second. Uses truncating division.

Params:
value The number of ticks to convert to seconds.

static long ticksToMS(long ticks);
Convert from TimeUnit.tick to TimeUnit.millisecond. Uses truncating division.

Params:
value The number of ticks to convert to milliseconds.

static long ticksToUS(long ticks);
Convert from TimeUnit.tick to TimeUnit.microsecond. Uses truncating division.

Params:
value The number of ticks to convert to microseconds.

enum UseLongName;
Whether the long display name or the short display name should be used.

string monthOfYearToString(MonthOfYear month, UseLongName useLong = (UseLongName).yes);
Returns the given month as a string.

Params:
MonthOfYear month The month to get the string for.
UseLongName useLong Whether the long or short version of the month name should be used.

Examples:
    assert(monthOfYearToString(january) == "January");
    assert(monthOfYearToString(january, UseLongName.no) == "Jan");
    assert(monthOfYearToString(july) == "July");
    assert(monthOfYearToString(july, UseLongName.no) == "Jul");


struct Date;
Represents a date in the propletic Gregorian Calendar ranging from 32,768 B.C. to 32,767 A.D. Positive years are A.D. Non-positive years are B.C.

Year, month, and day are kept separately internally so that Date is optimized for calendar operations.

Date uses the propletic Gregorian Calendar, so it assumes the leap year calculations for its entire length. As part of that, it also treats 1 B.C. as year 0, so 1 B.C. is 0, 2 B.C. is -1, etc. Use yearBC if want B.C. as a positive integer with 1 B.C. being the year prior to 1 A.D. Year 0 is a leap year.

this(Year year, MonthOfYear month, DayOfMonth day);
Params:
Year year Year of the Gregorian Calendar. Positive values are A.D. Non-positive values are B.C. with year 0 being the year prior to 1 A.D.
MonthOfYear month Month of the year.
DayOfMonth day Day of the month.

const int opCmp(in Date rhs);
Compares this Date with the given Date.

Returns:
this < rhs < 0
this == rhs 0
this > rhs > 0


const Year year();
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.

void year(Year year);
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.

Params:
Year year The year to set this Date's year to.

Examples:
        assert(Date(1999, 7, 6).year == 1999);
        assert(Date(2010, 10, 4).year == 2010);
        assert(Date(-7, 4, 5).year == -7);


const Year yearBC();
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C. An exception is thrown if isAD is true.

Examples:
        assert(Date(0, 1, 1).yearBC == 1);
        assert(Date(-1, 1, 1).yearBC == 2);
        assert(Date(-100, 1, 1).yearBC == 101);


void yearBC(Year year);
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C. An exception is thrown if a non-positive value is given.

Params:
Year year The year B.C. to set this Date's year to.

Examples:
        auto date = Date(2010, 1, 1);
        date.yearBC = 1;
        assert(date == Date(0, 1, 1));

        date.yearBC = 10;
        assert(date == Date(-9, 1, 1));


const MonthOfYear month();
Month of a Gregorian Year.

Examples:
        assert(Date(1999, 7, 6).month == 7);
        assert(Date(2010, 10, 4).month == 10);
        assert(Date(-7, 4, 5).month == 4);


void month(MonthOfYear month);
Month of a Gregorian Year.

Params:
mounth The month to set this Date's month to.

const DayOfMonth day();
Day of a Gregorian Month.

Examples:
        assert(Date(1999, 7, 6).day == 6);
        assert(Date(2010, 10, 4).day == 4);
        assert(Date(-7, 4, 5).day == 5);


void day(DayOfMonth day);
Day of a Gregorian Month.

Params:
DayOfMonth day The day of the month to set this Date's day to.

void addYears(int years, AllowDayOverflow allowOverflow = (AllowDayOverflow).yes);
Adds the given number of years to this Date. A negative number will subtract.

Note that if day overflow is allowed, and the date is Febuary 29th of a leap year, and the new year is not a leap year, then the date is shifted to March 1st. If day overflow is not allowed, then the date is shifted to February 28th.

Params:
int years The number of years to add to this Date.
AllowDayOverflow allowOverflow Whether the days should be allowed to overflow, causing the month to increment.

Examples:
        auto date1 = Date(2010, 1, 1);
        date1.addYears(1);
        assert(date1 == Date(2011, 1, 1));

        auto date2 = Date(2010, 1, 1);
        date2.addYears(-1);
        assert(date2 == Date(2009, 1, 1));

        auto date3 = Date(2000, 2, 29);
        date3.addYears(1);
        assert(date3 == Date(2001, 3, 1));

        auto date4 = Date(2000, 2, 29);
        date4.addYears(1, AllowDayOverflow.no);
        assert(date4 == Date(2001, 2, 28));


void addMonths(int months, AllowDayOverflow allowOverflow = (AllowDayOverflow).yes);
Adds the given number of months to this Date. A negative number will subtract.

The year will be adjusted along with the month if the number of months added (or subtracted) would overflow (or underflow) the current year.

Note that if day overflow is allowed, and the date with the adjusted month overflows the number of days in the new month, then the month will be incremented by one, and the days set to the number of days overflowed. (e.g. if the day were 31 and the new month were June, then the month would be incremented to July, and the new day would be 1). If day overflow is not allowed, then the day will be set to the last valid day in the month (e.g. June 31st would become June 30th).

Params:
int months The number of months to add to this Date.
AllowDayOverflow allowOverflow Whether the days should be allowed to overflow, causing the month to increment.

Examples:
        auto date1 = Date(2010, 1, 1);
        date1.addMonths(1);
        assert(date1 == Date(2010, 2, 1));

        auto date2 = Date(2010, 1, 1);
        date2.addMonths(-1);
        assert(date2 == Date(2009, 12, 1));

        auto date3 = Date(1999, 1, 29);
        date3.addMonths(1);
        assert(date3 == Date(1999, 3, 1));

        auto date4 = Date(1999, 1, 29);
        date4.addMonths(1, AllowDayOverflow.no);
        assert(date4 == Date(1999, 2, 28));


void addWeeks(long weeks);
Adds the given number of weeks to this Date. A negative number will subtract.

The day, month, and year will be adjusted accordingly.

addWeeks(numWeeks) is effectively equivalent to addDays(numWeeks * 7).

Note that addWeeks(52) is not equivalent to addYear(1) because a year does not have exactly 52 weeks.

Params:
long weeks The number of weeks to add to this Date.

Examples:
        auto date1 = Date(2010, 1, 1);
        auto date2 = date1;

        date1.addWeeks(1);
        date2.addDays(7);
        assert(date1 == date2);

        date1.addWeeks(52);
        date2.addYears(1);
        assert(date1 != date2);
        assert(date1 == Date(2011, 1, 7));
        assert(date2 == Date(2011, 1, 8));


void addDays(long days);
Adds the given number of days to this Date. A negative number will subtract.

The month will be adjusted along with the day if the number of days added (or subtracted) would overflow (or underflow) the current month. The year will be adjusted along with the month if the increase (or decrease) to the month would cause it to overflow (or underflow) the current year.

addDays(numDays) is effectively equivalent to date.dayOfGregorianCal = date.dayOfGregorianCal + days.

Params:
long days The number of days to add to this Date.

Examples:
        auto date = Date(2010, 1, 1);
        date.addDays(1);
        assert(date == Date(2010, 1, 2));
        date.addDays(365);
        assert(date == Date(2011, 1, 2));
        date.addDays(-32);
        assert(date == Date(2010, 12, 1));


void addTimeUnit(TimeUnit units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes);
Function for adding time units generically. The given TimeUnit must be TimeUnit.year, TimeUnit.month, TimeUnit.week, or TimeUnit.day.

Params:
units The type of unit to add to.
value The number of units to add to the given type of unit.
allowOverflow Whether the days should be allowed to overflow, causing the month to increment (only really applies to TimeUnit.year and TimeUnit.month, but addTimeUnit() is generic, so it's included; It's ignore otherwise).

Examples:
        addTimeUnit!(TimeUnit.year)(numYears);   //translates to addYears(numYears);
        addTimeUnit!(TimeUnit.month)(numMonths); //translates to addMonths(numMonths);
        addTimeUnit!(TimeUnit.week)(numWeeks);   //translates to addMonths(numWeeks);
        addTimeUnit!(TimeUnit.day)(numDays);     //translates to addMonths(numDays);


const bool isLeapYear();
Whether this Date is in a leap year.

const Tuple!(short,ubyte,ubyte) yearMonthDay();
Date as a tuple of year, month, and day.

const DayOfWeek dayOfWeek();
Day of the week.

const DayOfYear dayOfYear();
Day of the year this date is on.

Examples:
        assert(Date(1999, 1, 1).dayOfYear == 1);
        assert(Date(1999, 12, 31).dayOfYear == 365);
        assert(Date(2000, 12, 31).dayOfYear == 366);


void dayOfYear(DayOfYear day);
Day of the year.

Params:
DayOfYear day The day of the year to set which day of the year this Date is on.

const DayOfGregorianCal dayOfGregorianCal();
The Xth day of the Gregorian Calendar.

Examples:
        assert(Date(1, 1, 1).dayOfGregorianCal == 1);
        assert(Date(1, 12, 31).dayOfGregorianCal == 365);
        assert(Date(2, 1, 1).dayOfGregorianCal == 366);

        assert(Date(0, 12, 31).dayOfGregorianCal == 0);
        assert(Date(0, 1, 1).dayOfGregorianCal == -365);
        assert(Date(-1, 12, 31).dayOfGregorianCal == -366);

        assert(Date(2000, 1, 1).dayOfGregorianCal == 730_120);
        assert(Date(2010, 12, 31).dayOfGregorianCal == 734_137);


void dayOfGregorianCal(DayOfGregorianCal days);
The Xth day of the Gregorian Calendar.

Examples:
        auto date = Date.init;
        date.dayOfGregorianCal = 1;
        assert(date == Date(1, 1, 1));

        date.dayOfGregorianCal = 365;
        assert(date == Date(1, 12, 31));

        date.dayOfGregorianCal = 366;
        assert(date == Date(2, 1, 1));

        date.dayOfGregorianCal = 0;
        assert(date == Date(0, 12, 31));

        date.dayOfGregorianCal = -365;
        assert(date == Date(-0, 1, 1));

        date.dayOfGregorianCal = -366;
        assert(date == Date(-1, 12, 31));

        date.dayOfGregorianCal = 730_120;
        assert(date == Date(2000, 1, 1));

        date.dayOfGregorianCal = 734_137;
        assert(date == Date(2010, 12, 31));


const ISOWeek isoWeek();
The ISO 8601 week of the year that this Date is.

See Also:
ISO Week Date

const Date endOfMonth();
Date for the last day in the month that this Date is in.

Examples:
        assert(Date(1999, 1, 6).endOfMonth == Date(1999, 1, 31));
        assert(Date(1999, 2, 7).endOfMonth == Date(1999, 2, 28));
        assert(Date(2000, 2, 7).endOfMonth == Date(1999, 2, 29));
        assert(Date(2000, 6, 4).endOfMonth == Date(1999, 6, 30));


const DayOfMonth endOfMonthDay();
The last day in the month that this Date is in.

Examples:
        assert(Date(1999, 1, 6).endOfMonthDay == 31);
        assert(Date(1999, 2, 7).endOfMonthDay == 28);
        assert(Date(2000, 2, 7).endOfMonthDay == 29);
        assert(Date(2000, 6, 4).endOfMonthDay == 30);


const bool isAD();
Whether the current year is a date in A.D.

Examples:
        assert(Date(1, 1, 1).isAD);
        assert(Date(2010, 12, 31).isAD);
        assert(!Date(0, 12, 31).isAD);
        assert(!Date(-2010, 1, 1).isAD);


const bool isSpecial();
Returns true if isInfinity or isNAD are true.

const bool isInfinity();
Returns true if this date represents positive or negative infinity.

const bool isPosInfinity();
Returns true if this date represents positive.

const bool isNegInfinity();
Returns true if this date represents negative infinity.

const bool isNAD();
Returns true if this date is NAD (Not-a-Date), the Date equivalent of NAN.

const long julianDay();
The julian day for this Date at noon (since the julian day changes at noon).

const long modJulianDay();
The modified julian day for this Date at any time (since, the modified julian day changes at midnight).

const string toISOString();
Converts this Date to a string with the format YYYYMMDD.

Examples:
        assert(Date(2010, 7, 4).toISOString() == "20100704");
        assert(Date(1998, 12, 25).toISOString() == "19981225");
        assert(Date(0, 1, 5).toISOString() == "00000105");
        assert(Date(-4, 1, 5).toISOString() == "-00040105");


const string toISOExtendedString();
Converts this Date to a string with the format YYYY-MM-DD.

Examples:
        assert(Date(2010, 7, 4).toISOExtendedString() == "2010-07-04");
        assert(Date(1998, 12, 25).toISOExtendedString() == "1998-12-25");
        assert(Date(0, 1, 5).toISOExtendedString() == "0000-01-05");
        assert(Date(-4, 1, 5).toISOExtendedString() == "-0004-01-05");


const string toSimpleString();
Converts this Date to a string with the format YYYY-MonthShortName-DD.

Examples:
        assert(Date(2010, 7, 4).toSimpleString() == "2010-Jul-04");
        assert(Date(1998, 12, 25).toSimpleString() == "1998-Dec-25");
        assert(Date(0, 1, 5).toSimpleString() == "0000-Jan-05");
        assert(Date(-4, 1, 5).toSimpleString() == "-0004-Jan-05");


string toString();
Converts this Date to a string.

const string toString();
Converts this Date to a string.

static bool yearIsLeapYear(Year year);
Whether the given Year is a leap year.

static Date posInfinity();
Returns a Date for which isPosInfinity is true.

static Date negInfinity();
Returns a Date for which isNegInfinity is true.

static Date notADate();
Returns a Date for which isNAD is true.

static Date min();
Returns the Date farthest in the past which is representable by Date.

static Date max();
Returns the Date farthest in the future which is representable by Date.

static TimeUnit minResolution();
The lowest time resolution that Date has.

static TimeUnit maxResolution();
The highest time resolution that Date has.

struct TimeOfDay;
Represents a time of day with hours, minutes, and seconds. It uses 24 hour time.

this(Hour hours, Minute minutes, Second seconds = 0);
Params:
Hour hours Hour of the day [0 - 24).
Minute minutes Minute of the hour [0 - 60).
Second seconds Second of the minute [0 - 60).

const int opCmp(in TimeOfDay rhs);
Compares this TimeOfDay with the given TimeOfDay.

Returns:
this < rhs < 0
this == rhs 0
this > rhs > 0


const Hour hours();
Hours past midnight.

void hours(Hour hours);
Hours past midnight.

Params:
Hour hours The hours to set this TimeOfDay's hours to.

const Minute minutes();
Minutes past the current hour.

void minutes(Minute minutes);
Minutes past the current hour.

Params:
min The minutes to set this TimeOfDay's minutes to.

const Second seconds();
Seconds past the current minute.

void seconds(Second seconds);
Seconds past the current minute.

Params:
sec The seconds to set this TimeOfDay's seconds to.

void addHours(int hours);
Add hours to the time of day. Negative values will subtract. If the number of hours overflows or underflows, then the hours will wrap (e.g. adding 3 hours to 23:00 would result in 02:00).

Params:
int hours The number of hours to add to this TimeOfDay.

void addMinutes(int minutes);
Add minutes to the time of day. Negative values will subtract. If the number of minutes overflows (or underflows), then the minutes will wrap, increasing (or decreasing) the number of hours accordingly. If the number of hours overflows (or underflows), then the hours will wrap. (e.g. adding 90 minutes to 23:30 would result in 01:00).

Params:
int minutes The numbef or Minutes to add to this TimeOfDay.

void addSeconds(int seconds);
Add seconds to the time of day. Negative values will subtract. If the number of seconds overflows (or underflows), then the seconds will wrap, increasing (or decreasing) the number of minutes accordingly. If the number of minutes overflows (or underflows), then the minutes will wrap. If the number of minutes overflows(or underflows), then the hour will wrap. (e.g. adding 90 seconds to 23:59:00 would result in 00:00:30).

Params:
int seconds The number of seconds to add to this TimeOfDay.

void addTimeUnit(TimeUnit units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes);
Function for adding time units generically. The given TimeUnit must be TimeUnit.hour, TimeUnit. minute, or TimeUnit.second;

Params:
units The type of unit to add to.
value The number of units to add to the given type of unit.
allowOverflow Whether the days should be allowed to overflow, causing the month to increment (only really applies to TimeUnit.year and TimeUnit.month, but addTimeUnit() is generic, so it's included; However, it's ignored for TimeOfDay).

Examples:
        addTimeUnit!(TimeUnit.hour)(numHours);     //translates to addHours(numHours);
        addTimeUnit!(TimeUnit.minute)(numMinutes); //translates to addMinutes(numMinutes);
        addTimeUnit!(TimeUnit.second)(numSeconds); //translates to addSeconds(numSeconds);


const Tuple!(ubyte,ubyte,ubyte) hourMinSec();
TimeOfDay as a tuple of hour, minute, and second.

const string toISOString();
Converts this TimeOfDay to a string with the format HHMMSS.

Examples:
        assert(TimeOfDay(0, 0, 0).toISOString() == "000000");
        assert(TimeOfDay(12, 30, 33).toISOString() == "123033");


const string toISOExtendedString();
Converts this TimeOfDay to a string with the format HH:MM:SS.

Examples:
        assert(TimeOfDay(0, 0, 0).toISOExtendedString() == "000000");
        assert(TimeOfDay(12, 30, 33).toISOExtendedString() == "123033");


string toString();
Converts this TimeOfDay to a string.

const string toString();
Converts this TimeOfDay to a string.

static TimeOfDay min();
Returns midnight.

static TimeOfDay max();
Returns one second short of midnight.

static TimeUnit minResolution();
The lowest time resolution that TimeOfDay has.

static TimeUnit maxResolution();
The highest time resolution that TimeOfDay has.

struct DateTime;
Combines Date and TimeOfDay structs to give you an object which holds both the date and the time. It is optimized for calendar operations and has no concept of time zone. If you want an object which is optimized for time operations based on the system time, then use SysTime. SysTime has a concept of time zone and has much higher precision (ticks). DateTime is intended primarily for calendar-based uses rather than precise time operations.

this(in Date date, in TimeOfDay tod = (TimeOfDay).init);
Params:
Date date The date portion of DateTime.
TimeOfDay tod The time portion of DateTime.

this(Year year, MonthOfYear month, DayOfMonth day, Hour hours = 0, Minute minutes = 0, Second seconds = 0);
Params:
Year year The year portion of the date.
MonthOfYear month The month portion of the date.
DayOfMonth day The day portion of the date.
Hour hours The hour portion of the time;
Minute minutes The minute portion of the time;
Second seconds The second portion of the time;

const int opCmp(in DateTime rhs);
Compares this DateTime with the given DateTime.

Returns:
this < rhs < 0
this == rhs 0
this > rhs > 0


const Date date();
The date portion of DateTime.

void date(in Date date);
The date portion of DateTime.

Params:
Date date The Date to set this DateTime's Date portion to.

const TimeOfDay timeOfDay();
The time portion of DateTime.

void timeOfDay(in TimeOfDay tod);
The time portion of DateTime.

Params:
TimeOfDay tod The TimeOfDay to set this DateTime's TimeOfDay portion to.

const Year year();
See Also:
Date.year().

void year(Year year);
See Also:
Date.year().

const Year yearBC();
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C. An exception is thrown if isAD is true.

Examples:
        assert(DateTime(Date(0, 1, 1), TimeOfDay(12, 30, 33)).yearBC == 1);
        assert(DateTime(Date(-1, 1, 1), TimeOfDay(10, 7, 2)).yearBC == 2);
        assert(DateTime(Date(-100, 1, 1), TimeOfDay(4, 59, 0)).yearBC == 101);


void yearBC(Year year);
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C. An exception is thrown if a non-positive value is given.

Params:
Year year The year B.C. to set this Date's year to.

Examples:
        auto dt = DateTime(Date(2010, 1, 1), TimeOfDay(7, 30, 0));
        dt.yearBC = 1;
        assert(dt == DateTime(Date(0, 1, 1), TimeOfDay(7, 30, 0)));

        dt.yearBC = 10;
        assert(dt == DateTime(Date(-9, 1, 1), TimeOfDay(7, 30, 0)));


void month(MonthOfYear month);
See Also:
Date.month().

const DayOfMonth day();
See Also:
Date.day().

void day(DayOfMonth day);
See Also:
Date.addYears().

const Hour hours();
See Also:
TimeOfDay.hours().

void hours(Hour hours);
See Also:
TimeOfDay.hours().

const Minute minutes();
See Also:
TimeOfDay.minutes().

void minutes(Minute minutes);
See Also:
TimeOfDay.minutes().

const Second seconds();
See Also:
TimeOfDay.seconds().

void seconds(Second seconds);
See Also:
TimeOfDay.seconds().

void addYears(short years, AllowDayOverflow allowOverflow = (AllowDayOverflow).yes);
See Also:
Date.addYears().

void addMonths(int months, AllowDayOverflow allowOverflow = (AllowDayOverflow).yes);
See Also:
Date.addMonths().

void addWeeks(long weeks);
See Also:
Date.addWeeks().

void addDays(long days);
See Also:
Date.addDays().

void addHours(long hours);
Add hours to the time of day. Negative values will subtract. If the number of hours overflows or underflows, then the hours will wrap (e.g. adding 3 hours to 23:00 would result in 02:00). Also, if the number of hours wrap, then the day is incremented (or decremented) appropriately as well as any greater units if necessary.

Params:
long hours The number of hours to add to this DateTime.

void addMinutes(long minutes);
Add minutes to the time of day. Negative values will subtract. If the number of minutes overflows (or underflows), then the minutes will wrap, increasing (or decreasing) the number of hours accordingly. If the number of hours overflows (or underflows), then the hours will wrap. (e.g. adding 90 minutes to 23:30 would result in 01:00). Also, if the number of hours wrap, then the day is incremented (or decremented) appropriately as well as any greater units if necessary.

Params:
long minutes The numbef or minutes to add to this DateTime.

void addSeconds(long seconds);
Add seconds to the time of day. Negative values will subtract. If the number of seconds overflows (or underflows), then the seconds will wrap, increasing (or decreasing) the number of minutes accordingly. If the number of minutes overflows (or underflows), then the minutes will wrap. If the number of minutes overflows(or underflows), then the hour will wrap. (e.g. adding 90 seconds to 23:59:00 would result in 00:00:30). Also, if the number of hours wrap, then the day is incremented (or decremented) appropriately as well as any greater units if necessary.

Params:
long seconds The numbef or seconds to add to this DateTime.

void addTimeUnit(TimeUnit units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes);
Function for adding time units generically. The given TimeUnit must be TimeUnit.year, TimeUnit.month, TimeUnit.week, TimeUnit.day, TimeUnit.hour, TimeUnit. minute, or TimeUnit.second;

Params:
units The type of unit to add to.
value The number of units to add to the given type of unit.
allowOverflow Whether the days should be allowed to overflow, causing the month to increment (only really applies to TimeUnit.year and TimeUnit.month, but addTimeUnit() is generic, so it's included; It's ignore otherwise).

Examples:
        addTimeUnit!(TimeUnit.year)(numYears);     //translates to addYears(numYears);
        addTimeUnit!(TimeUnit.month)(numMonths);   //translates to addMonths(numMonths);
        addTimeUnit!(TimeUnit.week)(numWeeks);     //translates to addMonths(numWeeks);
        addTimeUnit!(TimeUnit.day)(numDays);       //translates to addDays(numDays);
        addTimeUnit!(TimeUnit.hour)(numHours);     //translates to addHours(numHours);
        addTimeUnit!(TimeUnit.minute)(numMinutes); //translates to addMinutes(numMinutes);
        addTimeUnit!(TimeUnit.second)(numSeconds); //translates to addSeconds(numSeconds);


const bool isLeapYear();
See Also:
Date.isLeapYear().

const Tuple!(short,ubyte,ubyte,ubyte,ubyte,ubyte) yearMonthDayHourMinSec();
DateTime as a tuple of year, month, day, hour, minute, and second.

const DayOfWeek dayOfWeek();
See Also:
Date.dayOfWeek().

const DayOfYear dayOfYear();
See Also:
Date.dayOfYear().

void dayOfYear(DayOfYear day);
See Also:
Date.dayOfYear().

const DayOfGregorianCal dayOfGregorianCal();
See Also:
Date.dayOfGregorianCal().

void dayOfGregorianCal(DayOfGregorianCal days);
See Also:
Date.dayOfGregorianCal().

const ISOWeek isoWeek();
See Also:
Date.isoWeek().

const DateTime endOfMonth();
TimeOfDay portion of endOfMonth is 23:59:59.

See Also:
Date.endOfMonth().

const DayOfMonth endOfMonthDay();
See Also:
Date.endOfMonthDay().

const bool isAD();
See Also:
Date.isAD().

const bool isSpecial();
Note that it is possible to set the Date portion of a special DateTime and make it so that it is a normal DateTime. However, you cannot set the TimeOfDay portion of a special DateTime. If you set the DateTime portion of a special DateTime, it's TimeOfDay portion will be TimeOfDay.init. It is also possible to make a normal DateTime special by setting its Date portion to a special date. Regardless, you cannot do anything with the TimeOfDay portion of a special Date.

See Also:
Date.isSpecial().

const bool isInfinity();
See Also:
Date.isInfinity().

const bool isPosInfinity();
See Also:
Date.isPosInfinity().

const bool isNegInfinity();
See Also:
Date.isNegInfinity().

const bool isNADT();
Returns true if this DateTime is NADT (Not-a-DateTime), the DateTime equivalent of NAN.

const long julianDay();
The julian day for this Date at the given time. For example, prior to noon, 1996-03-31 would be the julian day number 2450_173, so this function returns 2450_173, while from noon onward, it the julian day number would be 2450_174, so this function returns 2450_174.

const long modJulianDay();
See Also:
Date.modJulianDay().

const string toISOString();
Converts this DateTime to a string with the format YYYYMMDDTHHMMSS.

Examples:
        assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOString() == "20100704T070612");
        assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOString() == "19981225T021500");
        assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOString() == "00000105T230959");
        assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOString() == "-00040105T000002");


const string toISOExtendedString();
Converts this DateTime to a string with the format YYYY-MM-DDTHH:MM:SS.

Examples:
        assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOExtendedString() == "2010-07-04T07:06:12");
        assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOExtendedString() == "1998-12-25T02:15:00");
        assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOExtendedString() == "0000-01-05T23:09:59");
        assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOExtendedString() == "-0004-01-05T00:00:02");


const string toSimpleString();
Converts this DateTime to a string with the format YYYY-MonthShortName-DD HH:MM:SS.

Examples:
        assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toSimpleString() == "2010-Jul-04 07:06:12");
        assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toSimpleString() == "1998-Dec-25 02:15:00");
        assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toSimpleString() == "0000-Jan-05 23:09:59");
        assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toSimpleString() == "-0004-Jan-05 00:00:02");


string toString();
Converts this DateTime to a string.

const string toString();
Converts this DateTime to a string.

static DateTime posInfinity();
Returns a DateTime for which isPosInfinity is true.

static DateTime negInfinity();
Returns a DateTime for which isNegInfinity is true.

static DateTime notADateTime();
Returns a DateTime for which isNADT is true.

static DateTime min();
Returns the DateTime farthest in the past which is representable by DateTime.

static DateTime max();
Returns the DateTime farthest in the future which is representable by DateTime.

static TimeUnit minResolution();
The lowest time resolution that DateTime has.

static TimeUnit maxResolution();
The highest time resolution that DateTime has.


Page generated by Ddoc. Copyright Jonathan M Davis 2010