英語版
このページの英語版を見る
std.datetime.date
カテゴリー | 関数 |
---|---|
主な日付型 | Date DateTime |
その他の日付型 | Month DayOfWeek TimeOfDay |
日付チェック | valid validTimeUnits yearIsLeapYear isTimePoint enforceValid |
日付の変換 | daysToDayOfWeek monthsToMonth |
時間単位 | cmpTimeUnits timeStrings |
その他 | AllowDayOverflow DateTimeException |
License:
Authors:
- alias
DateTimeException
= core.time.TimeException; - std.datetimeで使用される例外型。これは core.time.TimeException.のエイリアスである。 どちらのモジュールから来たかを気にすることなくキャッチできる。
- enum
Month
: ubyte; - グレゴリオ暦の12ヶ月を表す(1月は1)。Examples:
writeln(Date(2018, 10, 1).month); // Month.oct writeln(DateTime(1, 1, 1).month); // Month.jan
jan
feb
mar
apr
may
jun
jul
aug
sep
oct
nov
dec
- enum
DayOfWeek
: ubyte; - グレゴリオ暦の週の7日間を表す(日曜日は0)。Examples:
writeln(Date(2018, 10, 1).dayOfWeek); // DayOfWeek.mon writeln(DateTime(5, 5, 5).dayOfWeek); // DayOfWeek.thu
sun
mon
tue
wed
thu
fri
sat
- alias
AllowDayOverflow
= std.typecons.Flag!"allowDayOverflow".Flag; - 一部の日付計算では、月や年を足すと、日付が有効でない月の日になることがある。 になることがある(たとえば2001年2月29日や2000年6月31日)。 2000年6月31日)。オーバーフローが許可されている場合(デフォルト)、月 はそれに応じてインクリメントされる(したがって、2001年2月29日は となり、2000年6月31日は2000年7月1日となる)。オーバーフロー が許可されていない場合、その日はその月の最後の有効な日に調整される。 そのため、2001年2月29日は2001年2月28日となり、2000年6月31日は2000年6月30日となる。 2000年6月31日は2000年6月30日となる)。AllowDayOverflowは、月または年を含む計算にのみ適用される。 もし
AllowDayOverflow
.noに設定されている場合、日数のオーバーフローは許可されない。 それ以外の場合AllowDayOverflow
.yesに設定された場合、日のオーバーフローは が許可される。 - immutable string[]
timeStrings
; - 時間単位を表す文字列の配列。 時間単位を表す文字列の配列。"nsecs" は含まない。"hnsecs" (ヘクトナノ秒(100 ns))を含む、 "usecs" (マイクロ秒)、"msecs" (ミリ秒)、"seconds" 、 "minutes" "hours" 、"days" 、"weeks" 、"months" 、および "years"
- struct
DateTime
; - を組み合わせる。 std.datetime.date.Dateそして std.datetime.date.TimeOfDay構造体を組み合わせ、日付と時刻の両方を保持するオブジェクトを生成する。 を持つオブジェクトを与える。これはカレンダーベースの操作に最適化されており に最適化されており、タイムゾーンの概念はない。システム時刻に基づく時刻操作に最適化された に最適化されたオブジェクトを使用する。 std.datetime.systime.SysTime. std.datetime.systime.SysTimeを使用する。 はタイムゾーンの概念を持ち、精度がはるかに高い(hnsecs)。
DateTime
は、正確な時間操作よりも、主にカレンダーベースの使用を意図している。 の操作に使用される。Examples:import core.time : days, seconds; auto dt = DateTime(2000, 6, 1, 10, 30, 0); writeln(dt.date); // Date(2000, 6, 1) writeln(dt.timeOfDay); // TimeOfDay(10, 30, 0) writeln(dt.dayOfYear); // 153 writeln(dt.dayOfWeek); // DayOfWeek.thu dt += 10.days + 100.seconds; writeln(dt); // DateTime(2000, 6, 11, 10, 31, 40) writeln(dt.toISOExtString()); // "2000-06-11T10:31:40" writeln(dt.toISOString()); // "20000611T103140" writeln(dt.toSimpleString()); // "2000-Jun-11 10:31:40" writeln(DateTime.fromISOExtString("2018-01-01T12:00:00")); // DateTime(2018, 1, 1, 12, 0, 0) writeln(DateTime.fromISOString("20180101T120000")); // DateTime(2018, 1, 1, 12, 0, 0) writeln(DateTime.fromSimpleString("2018-Jan-01 12:00:00")); // DateTime(2018, 1, 1, 12, 0, 0)
- pure nothrow @nogc @safe this(Date
date
, TimeOfDaytod
= TimeOfDay.init); - pure @safe this(int
year
, intmonth
, intday
, inthour
= 0, intminute
= 0, intsecond
= 0); - Parameters:
int year
日付の年部分。 int month
日付の月部分(1月は1)。 int day
日付の日部分。 int hour
時刻の時部分; int minute
分の部分 int second
時刻の秒の部分; - const pure nothrow @nogc @safe int
opCmp
(DateTimerhs
); - これを DateTimeを与えられたDateTime. と比較する。Returns:
this < rhs < 0 this == rhs 0 this > rhs > 0 - const pure nothrow @nogc @property @safe Date
date
(); - の日付部分は DateTime.
- pure nothrow @nogc @property @safe void
date
(Datedate
); - の日付部分である。 DateTime.Parameters:
Date date
この DateTimeの日付部分を設定する。 - const pure nothrow @nogc @property @safe TimeOfDay
timeOfDay
(); - の時間部分は DateTime.
- pure nothrow @nogc @property @safe void
timeOfDay
(TimeOfDaytod
); - の時間部分である。 DateTime.Parameters:
TimeOfDay tod
である。 std.datetime.date.TimeOfDayを設定する。 DateTimeの時間部分を設定する。 - const pure nothrow @nogc @property @safe short
year
(); - グレゴリオ暦の年。正の数は西暦である。 は紀元前である。
- pure @property @safe void
year
(intyear
); - グレゴリオ暦の年。正の数は西暦。 は紀元前である。Parameters:
int year
このDateTime 「年」を設定する。 Throws:std.datetime.date.DateTimeException 新しい年が 新年がうるう年でなく、結果として日付が2月29日になる場合。Examples:writeln(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).year); // 1999 writeln(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).year); // 2010 writeln(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).year); // -7
- const pure @property @safe short
yearBC
(); - グレゴリオ暦の紀元前0年を紀元前1年と数える。Throws:。std.datetime.date.DateTimeException isAD が真の場合Examples:
writeln(DateTime(Date(0, 1, 1), TimeOfDay(12, 30, 33)).yearBC); // 1 writeln(DateTime(Date(-1, 1, 1), TimeOfDay(10, 7, 2)).yearBC); // 2 writeln(DateTime(Date(-100, 1, 1), TimeOfDay(4, 59, 0)).yearBC); // 101
- pure @property @safe void
yearBC
(intyear
); - グレゴリオ暦の紀元前0年を紀元前1年と数える。Parameters:
int year
DateTime の西暦を紀元前に設定する 。Throws:std.datetime.date.DateTimeException 正の値でない場合 を指定する。Examples:auto dt = DateTime(Date(2010, 1, 1), TimeOfDay(7, 30, 0)); dt.yearBC = 1; writeln(dt); // DateTime(Date(0, 1, 1), TimeOfDay(7, 30, 0)) dt.yearBC = 10; writeln(dt); // DateTime(Date(-9, 1, 1), TimeOfDay(7, 30, 0))
- const pure nothrow @nogc @property @safe Month
month
(); - グレゴリオ暦の月。Examples:
writeln(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).month); // 7 writeln(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).month); // 10 writeln(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).month); // 4
- pure @property @safe void
month
(Monthmonth
); - グレゴリオ暦の月。Parameters:
Month month
この DateTimeに設定する。 Throws:std.datetime.date.DateTimeException指定された月が が有効な月でない場合は - const pure nothrow @nogc @property @safe ubyte
day
(); - グレゴリオ暦の月の日。Examples:
writeln(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).day); // 6 writeln(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).day); // 4 writeln(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).day); // 5
- pure @property @safe void
day
(intday
); - グレゴリオ暦の月の一日。Parameters:
int day
この DateTimeに設定する。 Throws:std.datetime.date.DateTimeException指定された日が でない場合は - const pure nothrow @nogc @property @safe ubyte
hour
(); - 午前0時を何時間も過ぎている。
- pure @property @safe void
hour
(inthour
); - 真夜中を何時間も過ぎた。Parameters:
int hour
この DateTimeに設定する。 Throws:std.datetime.date.DateTimeException指定された時間が 無効な DateTime. - const pure nothrow @nogc @property @safe ubyte
minute
(); - 時を数分過ぎた。
- pure @property @safe void
minute
(intminute
); - 時を数分過ぎた。Parameters:
int minute
この DateTimeに設定する。 Throws:std.datetime.date.DateTimeExceptionもし が無効な場合は DateTime. - const pure nothrow @nogc @property @safe ubyte
second
(); - 分1秒を過ぎた。
- pure @property @safe void
second
(intsecond
); - 分経過1秒Parameters:
int second
この DateTimeに設定する。 Throws:std.datetime.date.DateTimeExceptionもし が無効な場合は DateTime. - pure nothrow @nogc ref @safe DateTime
add
(string units)(longvalue
, AllowDayOverflowallowOverflow
= AllowDayOverflow.yes)
if (units == "years" || units == "months"); - このDateTime に、指定された年数または月数を加える、 を加える。負の数は減算される。日数のオーバーフローが許可されている場合、調整された年/月の日付が新しい月の日数をオーバーフローすることに注意すること。が新しい月の日数をオーバーフローする場合、月が1つインクリメントされ、月が1つインクリメントされる。 は1つインクリメントされ、日はオーバーフローした日数に設定される。 に設定される。(たとえば、日が31で新しい月が6月だった場合 月が7月になり、新しい日は1になる)。もし 日のオーバーフローが許可されていない場合、日はその月の最後の有効な日に設定される。 に設定される(例えば、6月31日は6月30日になる)。Parameters:
units 追加する単位の型(「年」または「月」) 。long value
追加する月または年の数。 DateTime. AllowDayOverflow allowOverflow
日数をオーバーフローさせるかどうか 、月をインクリメントする。 Returns:DateTime (this) への参照。Examples:auto dt1 = DateTime(2010, 1, 1, 12, 30, 33); dt1.add!"months"(11); writeln(dt1); // DateTime(2010, 12, 1, 12, 30, 33) auto dt2 = DateTime(2010, 1, 1, 12, 30, 33); dt2.add!"months"(-11); writeln(dt2); // DateTime(2009, 2, 1, 12, 30, 33) auto dt3 = DateTime(2000, 2, 29, 12, 30, 33); dt3.add!"years"(1); writeln(dt3); // DateTime(2001, 3, 1, 12, 30, 33) auto dt4 = DateTime(2000, 2, 29, 12, 30, 33); dt4.add!"years"(1, AllowDayOverflow.no); writeln(dt4); // DateTime(2001, 2, 28, 12, 30, 33)
- pure nothrow @nogc ref @safe DateTime
roll
(string units)(longvalue
, AllowDayOverflowallowOverflow
= AllowDayOverflow.yes)
if (units == "years" || units == "months"); - このDateTime に、指定された年数または月数を加える、 変異させる。負の数は引く。ローリングと加算の違いは、ローリングは大きな単位には影響しないということである。大きな単位には影響しないことである。DateTime 。 はまったく同じDateTime になる。ただし、各月の日数が異なるため ただし、各月の日数が異なるため、日数には影響がある。 年よりも大きな単位は存在しないため、年を足すことと転がすことに違いはない。 年を加算する場合と、年を繰り下げる場合の違いはない。Parameters:
units 追加する単位の型(「年」または「月」)。 long value
追加する月または年の数。 DateTime. AllowDayOverflow allowOverflow
日数をオーバーフローさせるかどうか 、月をインクリメントする。 Returns:DateTime (this) への参照。Examples:auto dt1 = DateTime(2010, 1, 1, 12, 33, 33); dt1.roll!"months"(1); writeln(dt1); // DateTime(2010, 2, 1, 12, 33, 33) auto dt2 = DateTime(2010, 1, 1, 12, 33, 33); dt2.roll!"months"(-1); writeln(dt2); // DateTime(2010, 12, 1, 12, 33, 33) auto dt3 = DateTime(1999, 1, 29, 12, 33, 33); dt3.roll!"months"(1); writeln(dt3); // DateTime(1999, 3, 1, 12, 33, 33) auto dt4 = DateTime(1999, 1, 29, 12, 33, 33); dt4.roll!"months"(1, AllowDayOverflow.no); writeln(dt4); // DateTime(1999, 2, 28, 12, 33, 33) auto dt5 = DateTime(2000, 2, 29, 12, 30, 33); dt5.roll!"years"(1); writeln(dt5); // DateTime(2001, 3, 1, 12, 30, 33) auto dt6 = DateTime(2000, 2, 29, 12, 30, 33); dt6.roll!"years"(1, AllowDayOverflow.no); writeln(dt6); // DateTime(2001, 2, 28, 12, 30, 33)
- pure nothrow @nogc ref @safe DateTime
roll
(string units)(longvalue
)
if (units == "days");
pure nothrow @nogc ref @safe DateTimeroll
(string units)(longvalue
)
if (units == "hours" || units == "minutes" || units == "seconds"); - このDateTime に指定された数のユニットを追加し、変異させる。A 負の数は引く。ローリングと加算の違いは、ローリングは大きなユニットに影響を与えないことである。大きなユニットに影響を与えないことである。たとえば、DateTime を1年分ロールする。 年分の日数をローリングすると、まったく同じDateTime になる。 使用可能な単位は、"days" 、"minutes" 、"hours" 、 "minutes" および"seconds" である。Parameters:
units 追加する単位。 long value
追加するユニット数 DateTime. Returns:DateTime (this) への参照。Examples:auto dt1 = DateTime(2010, 1, 1, 11, 23, 12); dt1.roll!"days"(1); writeln(dt1); // DateTime(2010, 1, 2, 11, 23, 12) dt1.roll!"days"(365); writeln(dt1); // DateTime(2010, 1, 26, 11, 23, 12) dt1.roll!"days"(-32); writeln(dt1); // DateTime(2010, 1, 25, 11, 23, 12) auto dt2 = DateTime(2010, 7, 4, 12, 0, 0); dt2.roll!"hours"(1); writeln(dt2); // DateTime(2010, 7, 4, 13, 0, 0) auto dt3 = DateTime(2010, 1, 1, 0, 0, 0); dt3.roll!"seconds"(-1); writeln(dt3); // DateTime(2010, 1, 1, 0, 0, 59)
- const pure nothrow @nogc @safe DateTime
opBinary
(string op)(Durationduration
)
if (op == "+" || op == "-"); - を加算または減算した結果を与える。core.time.Duration DateTime を加算または減算した結果を返す。この演算子を使ったDateTime の算術演算の型は以下の通りである。である。
。DateTime + Duration --> DateTime DateTime - 継続時間 --> DateTime Parameters:Duration duration
core.time.Duration から加減する。 このDateTime 。 Examples:import core.time : hours, seconds; assert(DateTime(2015, 12, 31, 23, 59, 59) + seconds(1) == DateTime(2016, 1, 1, 0, 0, 0)); assert(DateTime(2015, 12, 31, 23, 59, 59) + hours(1) == DateTime(2016, 1, 1, 0, 59, 59)); assert(DateTime(2016, 1, 1, 0, 0, 0) - seconds(1) == DateTime(2015, 12, 31, 23, 59, 59)); assert(DateTime(2016, 1, 1, 0, 59, 59) - hours(1) == DateTime(2015, 12, 31, 23, 59, 59));
- pure nothrow @nogc ref @safe DateTime
opOpAssign
(string op)(Durationduration
)
if (op == "+" || op == "-"); - に代入される。 DateTimeこの演算子 は
日付時刻 + 持続時間 --> DateTime DateTime - 継続時間 --> 日付 Parameters:Duration duration
を加算または減算する期間。 DateTime. - const pure nothrow @nogc @safe Duration
opBinary
(string op)(DateTimerhs
)
if (op == "-"); - の差を与える。 DateTimes.この演算子を使用できる算術演算の型は以下のとおりである。 DateTimeこの演算子を使用する
日付時刻 - 日付 --> 継続時間 - const pure nothrow @nogc @safe int
diffMonths
(DateTimerhs
); - 2つのDateTimeの差を月単位で返す。年単位で差を求めるには、2つの sの"@property"を引く。DateTimeを差し引く、 DateTime 。 core.time.Duration を使う。なぜなら 月とそれより小さい単位との間で変換するには、特定の日付が必要だからである。 core.time.Durationにはない)を必要とするため、月単位で差を求めるには、年単位と週単位の両方を使った計算が必要になる。 月の差を求めるには、年と月の両方のプロパティを使った計算が必要になる。 これは月の差を求めるための便利な関数である。 月の日数や月が何日目であるかは関係ないことに注意されたい。 は関係ない。これは月のプロパティの差である。 の差と年の差*12を組み合わせたものである。つまり、例えば 12月31日と1月1日は1ヶ月違いである。 と1月31日は1ヶ月違いである。Parameters:
DateTime rhs
DateTime ここから引く。 Examples:assert(DateTime(1999, 2, 1, 12, 2, 3).diffMonths( DateTime(1999, 1, 31, 23, 59, 59)) == 1); assert(DateTime(1999, 1, 31, 0, 0, 0).diffMonths( DateTime(1999, 2, 1, 12, 3, 42)) == -1); assert(DateTime(1999, 3, 1, 5, 30, 0).diffMonths( DateTime(1999, 1, 1, 2, 4, 7)) == 2); assert(DateTime(1999, 1, 1, 7, 2, 4).diffMonths( DateTime(1999, 3, 31, 0, 30, 58)) == -2);
- const pure nothrow @nogc @property @safe bool
isLeapYear
(); - 閏年かどうか DateTime閏年であるかどうか。
- const pure nothrow @nogc @property @safe DayOfWeek
dayOfWeek
(); - 曜日 DateTimeにある。
- const pure nothrow @nogc @property @safe ushort
dayOfYear
(); - このDateTime がオンになっている曜日。Examples:
writeln(DateTime(Date(1999, 1, 1), TimeOfDay(12, 22, 7)).dayOfYear); // 1 writeln(DateTime(Date(1999, 12, 31), TimeOfDay(7, 2, 59)).dayOfYear); // 365 writeln(DateTime(Date(2000, 12, 31), TimeOfDay(21, 20, 0)).dayOfYear); // 366
- pure @property @safe void
dayOfYear
(intday
); - 日である。Parameters:
int day
この日が1年のどの日にあたるかを設定する。 DateTimeを設定する。 - const pure nothrow @nogc @property @safe int
dayOfGregorianCal
(); - このDateTime 、グレゴリオ暦のX番目の日。Examples:
writeln(DateTime(Date(1, 1, 1), TimeOfDay(0, 0, 0)).dayOfGregorianCal); // 1 writeln(DateTime(Date(1, 12, 31), TimeOfDay(23, 59, 59)).dayOfGregorianCal); // 365 writeln(DateTime(Date(2, 1, 1), TimeOfDay(2, 2, 2)).dayOfGregorianCal); // 366 writeln(DateTime(Date(0, 12, 31), TimeOfDay(7, 7, 7)).dayOfGregorianCal); // 0 writeln(DateTime(Date(0, 1, 1), TimeOfDay(19, 30, 0)).dayOfGregorianCal); // -365 writeln(DateTime(Date(-1, 12, 31), TimeOfDay(4, 7, 0)).dayOfGregorianCal); // -366 writeln(DateTime(Date(2000, 1, 1), TimeOfDay(9, 30, 20)).dayOfGregorianCal); // 730_120 writeln(DateTime(Date(2010, 12, 31), TimeOfDay(15, 45, 50)).dayOfGregorianCal); // 734_137
- pure nothrow @nogc @property @safe void
dayOfGregorianCal
(intdays
); -
Parameters:
int days
に設定するグレゴリオ暦の日。DateTime に設定する。 Examples:auto dt = DateTime(Date.init, TimeOfDay(12, 0, 0)); dt.dayOfGregorianCal = 1; writeln(dt); // DateTime(Date(1, 1, 1), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = 365; writeln(dt); // DateTime(Date(1, 12, 31), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = 366; writeln(dt); // DateTime(Date(2, 1, 1), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = 0; writeln(dt); // DateTime(Date(0, 12, 31), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = -365; writeln(dt); // DateTime(Date(-0, 1, 1), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = -366; writeln(dt); // DateTime(Date(-1, 12, 31), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = 730_120; writeln(dt); // DateTime(Date(2000, 1, 1), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = 734_137; writeln(dt); // DateTime(Date(2010, 12, 31), TimeOfDay(12, 0, 0))
- const pure nothrow @property @safe ubyte
isoWeek
(); - その年のISO 8601週。 DateTimeである。See Also:
- const pure nothrow @property @safe short
isoWeekYear
(); - ISO8601週カレンダーの年。 DateTimeである。See Also:
- const pure nothrow @property @safe DateTime
endOfMonth
(); - Examples:
assert(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).endOfMonth == DateTime(Date(1999, 1, 31), TimeOfDay(23, 59, 59))); assert(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).endOfMonth == DateTime(Date(1999, 2, 28), TimeOfDay(23, 59, 59))); assert(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).endOfMonth == DateTime(Date(2000, 2, 29), TimeOfDay(23, 59, 59))); assert(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).endOfMonth == DateTime(Date(2000, 6, 30), TimeOfDay(23, 59, 59)));
- const pure nothrow @nogc @property @safe ubyte
daysInMonth
(); - このDateTime がある月の最終日。Examples:
writeln(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).daysInMonth); // 31 writeln(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).daysInMonth); // 28 writeln(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).daysInMonth); // 29 writeln(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).daysInMonth); // 30
- const pure nothrow @nogc @property @safe bool
isAD
(); - 現在の年が西暦の日付であるかどうか。Examples:
assert(DateTime(Date(1, 1, 1), TimeOfDay(12, 7, 0)).isAD); assert(DateTime(Date(2010, 12, 31), TimeOfDay(0, 0, 0)).isAD); assert(!DateTime(Date(0, 12, 31), TimeOfDay(23, 59, 59)).isAD); assert(!DateTime(Date(-2010, 1, 1), TimeOfDay(2, 2, 2)).isAD);
- const pure nothrow @nogc @property @safe long
julianDay
(); - const pure nothrow @nogc @property @safe long
modJulianDay
(); - を返す。 この日付の任意の時刻の修正ユリウス日(修正ユリウス日は午前0時に変更されるため)。
- const pure nothrow @safe string
toISOString
();
const voidtoISOString
(W)(ref Wwriter
)
if (isOutputRange!(W, char)); -
Parameters:
W writer
char 。 出力範囲 Returns:出力範囲を使用しない場合はstring 、そうでない場合はvoid 。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 pure nothrow @safe string
toISOExtString
();
const voidtoISOExtString
(W)(ref Wwriter
)
if (isOutputRange!(W, char)); -
Parameters:
W writer
char 。 出力範囲 Returns:出力範囲を使用しない場合はstring 、そうでない場合はvoid 。Examples:assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOExtString() == "2010-07-04T07:06:12"); assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOExtString() == "1998-12-25T02:15:00"); assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOExtString() == "0000-01-05T23:09:59"); assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOExtString() == "-0004-01-05T00:00:02");
- const pure nothrow @safe string
toSimpleString
();
const voidtoSimpleString
(W)(ref Wwriter
)
if (isOutputRange!(W, char)); -
Parameters:
W writer
char 。 出力範囲 Returns:出力範囲を使用しない場合はstring 、そうでない場合はvoid 。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");
- const pure nothrow @safe string
toString
();
const voidtoString
(W)(ref Wwriter
)
if (isOutputRange!(W, char)); - を文字列に変換する。 DateTimeを文字列に変換する。を簡単に変換するためにこの関数が存在する。 DateTimeを を簡単に文字列に変換するために存在する。 この関数は、正確な書式を気にしないコードに対して、情報をわかりやすく表示するために存在する。また を単純に文字列に変換する DateTimeを文字列に変換するのも簡単になる。 to!string 、format 、writeln など、toStringを使ってユーザー定義型を変換する関数を使う場合、aを単純に文字列に変換することも簡単になる。 のようなユーザー定義型を変換する関数を使うときにも、簡単にaを文字列に変換することができる。そのため、多くのコードで を直接呼び出すことはあまりないだろう。 文字列のフォーマットは意図的に指定されていない。 文字列の書式を気にするコードは、toISOString 、 toISOExtString toSimpleString 、またはその他のカスタム書式設定関数を使うべきである。 関数を使うべきである。その理由は その理由は、コードがどの書式を使用しているかが明確になるからだ、 コードの保守や、生成された文字列を消費する他のソフトウェアとのやり取りで、エラーが発生しにくくなるからだ。 とのやりとりにエラーが発生しにくくなるからだ。これと同じ理由で 同じ理由で DateTimeにはfromString 関数がない。 fromISOString fromISOExtString とfromSimpleString がある。 toStringが返すフォーマットは、将来変更されるかもしれないし、変更されないかもしれない。
- pure @safe DateTime
fromISOString
(S)(scope const SisoString
)
if (isSomeString!S); - YYYYMMDDTHHMMSS形式の文字列から DateTimeを作成する。 与えられた文字列から空白が取り除かれる。Parameters:
S isoString
日付と時刻の ISO フォーマットでフォーマットされた文字列。 Throws:std.datetime.date.DateTimeException与えられた文字列が でない場合、あるいは DateTimeが有効でない場合は は有効でない。 - pure @safe DateTime
fromISOExtString
(S)(scope const SisoExtString
)
if (isSomeString!S); - を作成する。 DateTimeを作成する。 yyyy-mm-ddthh:mm:ss。与えられた文字列から空白が取り除かれる。Parameters:
S isoExtString
日付と時刻の ISO 拡張書式でフォーマットされた文字列 でフォーマットされた文字列。 Throws:std.datetime.date.DateTimeException与えられた文字列が がISO拡張形式でない場合、あるいは DateTime が有効でない場合は - pure @safe DateTime
fromSimpleString
(S)(scope const SsimpleString
)
if (isSomeString!S); - を作成する。 DateTimeを作成する。 YYYY-Mon-DD HH:MM:SS。指定された文字列から空白が取り除かれる。Parameters:
S simpleString
toSimpleStringが日付と時刻をフォーマットする方法でフォーマットされた文字列。 が日付と時刻をフォーマットする方法でフォーマットされた文字列。 Throws:std.datetime.date.DateTimeException与えられた文字列が が正しい書式でない場合、あるいは DateTime が有効でない場合 - static pure nothrow @nogc @property @safe DateTime
min
(); - static pure nothrow @nogc @property @safe DateTime
max
();
- struct
Date
; - 年、月、日は内部で別々に管理されている。
Date
である。 暦に基づく操作に最適化されている。Date
はプロレプティック・グレゴリオ暦を使用しているため、全期間にわたってグレゴリオ暦の閏年計算を想定している。 閏年の計算を想定している。ISO8601では ISO 8601に基づき、紀元前1年を0年として扱う。 つまり、紀元前1年を0年、紀元前2年を-1年とする。を使用する。 yearBCを使用する。 を正の整数として使用する。 0年はうるう年である。Examples:import core.time : days; auto d = Date(2000, 6, 1); writeln(d.dayOfYear); // 153 writeln(d.dayOfWeek); // DayOfWeek.thu d += 10.days; writeln(d); // Date(2000, 6, 11) writeln(d.toISOExtString()); // "2000-06-11" writeln(d.toISOString()); // "20000611" writeln(d.toSimpleString()); // "2000-Jun-11" writeln(Date.fromISOExtString("2018-01-01")); // Date(2018, 1, 1) writeln(Date.fromISOString("20180101")); // Date(2018, 1, 1) writeln(Date.fromSimpleString("2018-Jan-01")); // Date(2018, 1, 1)
- pure @safe this(int
year
, intmonth
, intday
); - Throws:std.datetime.date.DateTimeExceptionもし Dateは無効となる。Parameters:
int year
グレゴリオ暦の年。正の値は西暦。 正の値以外は紀元前で、0年は紀元1年の前の年である。 西暦1年より前の年である。 int month
月(1月は1)。 int day
月の日。 - pure nothrow @nogc @safe this(int
day
); - Parameters:
int day
グレゴリオ暦X月X日。 Dateを指定する。 - const pure nothrow @nogc @safe int
opCmp
(Daterhs
); - Returns:
this < rhs < 0 this == rhs 0 this > rhs > 0 - const pure nothrow @nogc @property @safe short
year
(); - グレゴリオ暦の年。正の数は西暦である。 は紀元前である。Examples:
writeln(Date(1999, 7, 6).year); // 1999 writeln(Date(2010, 10, 4).year); // 2010 writeln(Date(-7, 4, 5).year); // -7
- pure @property @safe void
year
(intyear
); - グレゴリオ暦の年。正の数は西暦である。 は紀元前である。Parameters:
int year
この日付の年を設定する。 Throws:std.datetime.date.DateTimeException 新しい年が 新年がうるう年でなく、結果として日付が2月29日になる場合。Examples:writeln(Date(1999, 7, 6).year); // 1999 writeln(Date(2010, 10, 4).year); // 2010 writeln(Date(-7, 4, 5).year); // -7
- const pure @property @safe ushort
yearBC
(); - グレゴリオ暦の紀元前0年を紀元前1年と数える。Throws:。std.datetime.date.DateTimeException isAD が真の場合Examples:
writeln(Date(0, 1, 1).yearBC); // 1 writeln(Date(-1, 1, 1).yearBC); // 2 writeln(Date(-100, 1, 1).yearBC); // 101
- pure @property @safe void
yearBC
(intyear
); - グレゴリオ暦の紀元前0年を紀元前1年と数える。Parameters:
int year
Date の西暦を紀元前に設定する 。Throws:std.datetime.date.DateTimeException 正の値でない場合 を指定する。Examples:auto date = Date(2010, 1, 1); date.yearBC = 1; writeln(date); // Date(0, 1, 1) date.yearBC = 10; writeln(date); // Date(-9, 1, 1)
- const pure nothrow @nogc @property @safe Month
month
(); - グレゴリオ暦の月。Examples:
writeln(Date(1999, 7, 6).month); // 7 writeln(Date(2010, 10, 4).month); // 10 writeln(Date(-7, 4, 5).month); // 4
- pure @property @safe void
month
(Monthmonth
); - グレゴリオ暦の月。Parameters:
Month month
この Dateに設定する。 Throws:std.datetime.date.DateTimeException指定された月が が有効な月でない場合、あるいは現在の日が指定された を指定する。 - const pure nothrow @nogc @property @safe ubyte
day
(); - グレゴリオ暦の月の日。Examples:
writeln(Date(1999, 7, 6).day); // 6 writeln(Date(2010, 10, 4).day); // 4 writeln(Date(-7, 4, 5).day); // 5
- pure @property @safe void
day
(intday
); - グレゴリオ暦の月の一日。Parameters:
int day
この Dateに設定する。 Throws:std.datetime.date.DateTimeException指定された日が でない場合は - pure nothrow @nogc ref @safe Date
add
(string units)(longvalue
, AllowDayOverflowallowOverflow
= AllowDayOverflow.yes)
if (units == "years"); - このDate 、指定された年数または月数を追加する。 する。負の数は減算される。日数のオーバーフローが許可されている場合、調整された年/月の日付が新しい月の日数をオーバーフローすることに注意すること。が新しい月の日数をオーバーフローする場合、月が1つインクリメントされ、月が1つインクリメントされる。 は1つインクリメントされ、日はオーバーフローした日数に設定される。 に設定される。(たとえば、日が31で新しい月が6月だった場合 月が7月になり、新しい日は1になる)。もし 日のオーバーフローが許可されていない場合、日はその月の最後の有効な日に設定される。 に設定される(例えば、6月31日は6月30日になる)。Parameters:
units 追加する単位の型(「年」または「月」) 。long value
追加する月または年の数。 Date. AllowDayOverflow allowOverflow
日をオーバーフローさせるかどうか 、月をインクリメントする。 Returns:Date (this) への参照。Examples:auto d1 = Date(2010, 1, 1); d1.add!"months"(11); writeln(d1); // Date(2010, 12, 1) auto d2 = Date(2010, 1, 1); d2.add!"months"(-11); writeln(d2); // Date(2009, 2, 1) auto d3 = Date(2000, 2, 29); d3.add!"years"(1); writeln(d3); // Date(2001, 3, 1) auto d4 = Date(2000, 2, 29); d4.add!"years"(1, AllowDayOverflow.no); writeln(d4); // Date(2001, 2, 28)
- pure nothrow @nogc ref @safe Date
roll
(string units)(longvalue
, AllowDayOverflowallowOverflow
= AllowDayOverflow.yes)
if (units == "years"); - このDate 、指定された年数または月数を追加する。 する。負の数は引く。ローリングと加算の違いは、ローリングは大きな単位には影響しないということである。大きな単位には影響しないことである。Date を12ヶ月ロールすると、まったく同じ が得られる。 はまったく同じDate になる。ただし、各月の日数が異なるため、日数には影響がある。 ただし、各月の日数が異なるため、日数には影響がある。 年よりも大きな単位は存在しないため、年を足すことと転がすことに違いはない。 年を加算する場合と、年を繰り下げる場合の違いはない。Parameters:
units 追加する単位の型(「年」または「月」)。 long value
追加する月または年の数。 Date. AllowDayOverflow allowOverflow
日をオーバーフローさせるかどうか 、月をインクリメントする。 Returns:Date (this) への参照。Examples:auto d1 = Date(2010, 1, 1); d1.roll!"months"(1); writeln(d1); // Date(2010, 2, 1) auto d2 = Date(2010, 1, 1); d2.roll!"months"(-1); writeln(d2); // Date(2010, 12, 1) auto d3 = Date(1999, 1, 29); d3.roll!"months"(1); writeln(d3); // Date(1999, 3, 1) auto d4 = Date(1999, 1, 29); d4.roll!"months"(1, AllowDayOverflow.no); writeln(d4); // Date(1999, 2, 28) auto d5 = Date(2000, 2, 29); d5.roll!"years"(1); writeln(d5); // Date(2001, 3, 1) auto d6 = Date(2000, 2, 29); d6.roll!"years"(1, AllowDayOverflow.no); writeln(d6); // Date(2001, 2, 28)
- pure nothrow @nogc ref @safe Date
roll
(string units)(longdays
)
if (units == "days
"); - このDate に指定された数のユニットを追加し、変異させる。A 負の数は引く。ローリングと加算の違いは、ローリングは大きなユニットに影響を与えないことである。Parameters:
units 追加する単位。" days
" でなければならない。long days
このDate に追加する日数。 Returns:Date (this) への参照。Examples:auto d = Date(2010, 1, 1); d.roll!"days"(1); writeln(d); // Date(2010, 1, 2) d.roll!"days"(365); writeln(d); // Date(2010, 1, 26) d.roll!"days"(-32); writeln(d); // Date(2010, 1, 25)
- const pure nothrow @nogc @safe Date
opBinary
(string op)(Durationduration
)
if (op == "+" || op == "-"); - を加算または減算した結果を返す。core.time.Duration を加算または減算した結果を返す。この演算子を使用したDate の算術演算は以下の通りである。
日付 + 期間 --> 日付 日付 - 継続時間 --> 日付 Parameters:Duration duration
core.time.Duration を加減する。 このDate 。 Examples:import core.time : days; writeln(Date(2015, 12, 31) + days(1)); // Date(2016, 1, 1) writeln(Date(2004, 2, 26) + days(4)); // Date(2004, 3, 1) writeln(Date(2016, 1, 1) - days(1)); // Date(2015, 12, 31) writeln(Date(2004, 3, 1) - days(4)); // Date(2004, 2, 26)
- pure nothrow @nogc ref @safe Date
opOpAssign
(string op)(Durationduration
)
if (op == "+" || op == "-"); - に代入する。 Dateこの演算子を使用する
日付 + 期間 --> 日付 日付 - 期間 --> 日付 Parameters:Duration duration
その core.time.Durationで加減する。 この Date. - const pure nothrow @nogc @safe Duration
opBinary
(string op)(Daterhs
)
if (op == "-"); - の差を与える。 Dates.この演算子を使用できる算術演算の型は以下のとおりである。 Dateこの演算子を使用する
日付 - 日付 --> 存続期間 - const pure nothrow @nogc @safe int
diffMonths
(Daterhs
); - 2つのDateの差を月単位で返す。年単位で差を求めるには、2つの sの"@property"を引く。Dateを差し引く、 Date 。 core.time.Duration を使う。なぜなら 月とそれより小さい単位との間で変換するには、特定の日付が必要だからである。 core.time.Durationにはない)を必要とするため、月単位で差を求めるには、年単位と週単位の両方を使った計算が必要になる。 月の差を求めるには、年と月の両方のプロパティを使った計算が必要になる。 これは月の差を求めるための便利な関数である。 月の日数や月がどの程度進んでいるかは関係ないことに注意されたい。 Date 。これは月の差である。 プロパティの差である。つまり、例えば 12月31日と1月1日は1ヶ月違いである。 と1月31日は1ヶ月違いである。Parameters:
Date rhs
Date ここから引く。 Examples:writeln(Date(1999, 2, 1).diffMonths(Date(1999, 1, 31))); // 1 writeln(Date(1999, 1, 31).diffMonths(Date(1999, 2, 1))); // -1 writeln(Date(1999, 3, 1).diffMonths(Date(1999, 1, 1))); // 2 writeln(Date(1999, 1, 1).diffMonths(Date(1999, 3, 31))); // -2
- const pure nothrow @nogc @property @safe bool
isLeapYear
(); - 閏年かどうか Date閏年であるかどうか。
- const pure nothrow @nogc @property @safe DayOfWeek
dayOfWeek
(); - 曜日 Dateにある。
- const pure nothrow @nogc @property @safe ushort
dayOfYear
(); - このDate がオンになっている曜日。Examples:
writeln(Date(1999, 1, 1).dayOfYear); // 1 writeln(Date(1999, 12, 31).dayOfYear); // 365 writeln(Date(2000, 12, 31).dayOfYear); // 366
- pure @property @safe void
dayOfYear
(intday
); - 日である。Parameters:
int day
この日が1年のどの日にあたるかを設定する。 Dateを設定する。 Throws:std.datetime.date.DateTimeException指定された日が が無効な場合 - const pure nothrow @nogc @property @safe int
dayOfGregorianCal
(); - このDate 、グレゴリオ暦のX日目。Examples:
writeln(Date(1, 1, 1).dayOfGregorianCal); // 1 writeln(Date(1, 12, 31).dayOfGregorianCal); // 365 writeln(Date(2, 1, 1).dayOfGregorianCal); // 366 writeln(Date(0, 12, 31).dayOfGregorianCal); // 0 writeln(Date(0, 1, 1).dayOfGregorianCal); // -365 writeln(Date(-1, 12, 31).dayOfGregorianCal); // -366 writeln(Date(2000, 1, 1).dayOfGregorianCal); // 730_120 writeln(Date(2010, 12, 31).dayOfGregorianCal); // 734_137
- pure nothrow @nogc @property @safe void
dayOfGregorianCal
(intday
); - このDate が表示しているグレゴリオ暦のX日。Parameters:
int day
このDate を設定するグレゴリオ暦の日。 Examples:auto date = Date.init; date.dayOfGregorianCal = 1; writeln(date); // Date(1, 1, 1) date.dayOfGregorianCal = 365; writeln(date); // Date(1, 12, 31) date.dayOfGregorianCal = 366; writeln(date); // Date(2, 1, 1) date.dayOfGregorianCal = 0; writeln(date); // Date(0, 12, 31) date.dayOfGregorianCal = -365; writeln(date); // Date(-0, 1, 1) date.dayOfGregorianCal = -366; writeln(date); // Date(-1, 12, 31) date.dayOfGregorianCal = 730_120; writeln(date); // Date(2000, 1, 1) date.dayOfGregorianCal = 734_137; writeln(date); // Date(2010, 12, 31)
- const pure nothrow @property @safe auto
isoWeekAndYear
(); - ISO8601の週と年。 Dateである。Returns:匿名構造体で、メンバはisoWeekYear である。 isoWeek メンバを持つ匿名構造体。See Also:
- const pure nothrow @property @safe ubyte
isoWeek
(); - ISO8601の週。 Dateである。See Also:
- const pure nothrow @property @safe short
isoWeekYear
(); - ISO 8601の週カレンダーの中の年。 Dateである。12月28日と yearと異なる場合がある。See Also:
- const pure nothrow @property @safe Date
endOfMonth
(); - Examples:
writeln(Date(1999, 1, 6).endOfMonth); // Date(1999, 1, 31) writeln(Date(1999, 2, 7).endOfMonth); // Date(1999, 2, 28) writeln(Date(2000, 2, 7).endOfMonth); // Date(2000, 2, 29) writeln(Date(2000, 6, 4).endOfMonth); // Date(2000, 6, 30)
- const pure nothrow @nogc @property @safe ubyte
daysInMonth
(); - このDate が属する月の最終日。Examples:
writeln(Date(1999, 1, 6).daysInMonth); // 31 writeln(Date(1999, 2, 7).daysInMonth); // 28 writeln(Date(2000, 2, 7).daysInMonth); // 29 writeln(Date(2000, 6, 4).daysInMonth); // 30
- const pure nothrow @nogc @property @safe bool
isAD
(); - 現在の年が西暦の日付であるかどうか。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 pure nothrow @nogc @property @safe long
julianDay
(); - const pure nothrow @nogc @property @safe long
modJulianDay
(); - 修正ユリウス日 この日付の任意の時刻の修正ユリウス日(修正ユリウス日は午前0時に変わるので で変更されるため)。
- const pure nothrow @safe string
toISOString
();
const voidtoISOString
(W)(ref Wwriter
)
if (isOutputRange!(W, char)); -
Parameters:
W writer
char 、出力範囲を受け付ける Returns:出力範囲を使用しない場合はstring 、そうでない場合はvoid 。Examples:writeln(Date(2010, 7, 4).toISOString()); // "20100704" writeln(Date(1998, 12, 25).toISOString()); // "19981225" writeln(Date(0, 1, 5).toISOString()); // "00000105" writeln(Date(-4, 1, 5).toISOString()); // "-00040105"
- const pure nothrow @safe string
toISOExtString
();
const voidtoISOExtString
(W)(ref Wwriter
)
if (isOutputRange!(W, char)); -
Parameters:
W writer
char 、出力範囲を受け付ける Returns:出力範囲を使用しない場合はstring 、そうでない場合はvoid 。Examples:writeln(Date(2010, 7, 4).toISOExtString()); // "2010-07-04" writeln(Date(1998, 12, 25).toISOExtString()); // "1998-12-25" writeln(Date(0, 1, 5).toISOExtString()); // "0000-01-05" writeln(Date(-4, 1, 5).toISOExtString()); // "-0004-01-05"
- const pure nothrow @safe string
toSimpleString
();
const voidtoSimpleString
(W)(ref Wwriter
)
if (isOutputRange!(W, char)); - Parameters:
W writer
char 出力範囲 Returns:出力レンジを使用しない場合はstring 、それ以外はvoid 。Examples:writeln(Date(2010, 7, 4).toSimpleString()); // "2010-Jul-04" writeln(Date(1998, 12, 25).toSimpleString()); // "1998-Dec-25" writeln(Date(0, 1, 5).toSimpleString()); // "0000-Jan-05" writeln(Date(-4, 1, 5).toSimpleString()); // "-0004-Jan-05"
- const pure nothrow @safe string
toString
();
const voidtoString
(W)(ref Wwriter
)
if (isOutputRange!(W, char)); - を文字列に変換する。 Dateを文字列に変換する。を簡単に変換するためにこの関数が存在する。 Dateを を簡単に文字列に変換するために存在する。 この関数は、正確な書式を気にしないコードに対して、情報をわかりやすく表示するために存在する。また を単純に文字列に変換する Dateを文字列に変換することも簡単になる。 to!string やformat 、writeln のような関数を使うときに、aを単純に文字列に変換することも簡単になる。 のようなユーザー定義型を変換する関数を使うときにも、簡単にaを文字列に変換することができる。そのため、多くのコードで を直接呼び出すことはあまりないだろう。 文字列のフォーマットは意図的に指定されていない。 文字列の書式を気にするコードは、toISOString 、 toISOExtString toSimpleString 、またはその他のカスタム書式設定関数を使うべきである。 関数を使うべきである。その理由は その理由は、コードがどの書式を使用しているかが明確になるからだ、 コードの保守や、生成された文字列を消費する他のソフトウェアとのやり取りで、エラーが発生しにくくなるからだ。 とのやりとりにエラーが発生しにくくなるからだ。これと同じ理由で DateにはfromString 関数がない。 fromISOString fromISOExtString とfromSimpleString がある。 toStringが返す書式は、将来変更されるかもしれないし、変更されないかもしれない。
- pure @safe Date
fromISOString
(S)(scope const SisoString
)
if (isSomeString!S); - YYYYMMDD形式の文字列から Dateを作成する。空白 は与えられた文字列から取り除かれる。Parameters:
S isoString
ISO 形式でフォーマットされた日付文字列。 Throws:std.datetime.date.DateTimeException与えられた文字列が でない場合、あるいは Dateが 有効な - pure @safe Date
fromISOExtString
(S)(scope const SisoExtString
)
if (isSomeString!S); - YYYY-MM-DD形式の文字列から Dateを作成する。 与えられた文字列から空白が取り除かれる。Parameters:
S isoExtString
ISO 拡張書式でフォーマットされた文字列。 日付。 Throws:std.datetime.date.DateTimeException与えられた文字列が がISO拡張形式でない場合、あるいは Date が有効でない場合は - pure @safe Date
fromSimpleString
(S)(scope const SsimpleString
)
if (isSomeString!S); - YYYY-Mon-DD形式の文字列から Dateを作成する。 与えられた文字列から空白が取り除かれる。Parameters:
S simpleString
toSimpleStringが日付をフォーマットする方法でフォーマットされた文字列。 が日付をフォーマットする方法でフォーマットされた文字列。 Throws:std.datetime.date.DateTimeException与えられた文字列が が正しい書式でない場合、あるいは Dateが有効でない場合は を返す。 - static pure nothrow @nogc @property @safe Date
min
(); - static pure nothrow @nogc @property @safe Date
max
();
- struct
TimeOfDay
; - 時、分、秒で時刻を表す。24時間 時間である。Examples:
import core.time : minutes, seconds; auto t = TimeOfDay(12, 30, 0); t += 10.minutes + 100.seconds; writeln(t); // TimeOfDay(12, 41, 40) writeln(t.toISOExtString()); // "12:41:40" writeln(t.toISOString()); // "124140" writeln(TimeOfDay.fromISOExtString("15:00:00")); // TimeOfDay(15, 0, 0) writeln(TimeOfDay.fromISOString("015000")); // TimeOfDay(1, 50, 0)
- pure @safe this(int
hour
, intminute
, intsecond
= 0); - Parameters:
int hour
時間 [0 - 24]。 int minute
時[0 - 60]の分。 int second
分の秒 [0 - 60]。 Throws:std.datetime.date.DateTimeException結果として TimeOfDayは無効となる。 - const pure nothrow @nogc @safe int
opCmp
(TimeOfDayrhs
); - Returns:
this < rhs < 0 this == rhs 0 this > rhs > 0 - const pure nothrow @nogc @property @safe ubyte
hour
(); - 午前0時を何時間も過ぎている。
- pure @property @safe void
hour
(inthour
); - 午前0時を何時間も過ぎている。Parameters:
int hour
この TimeOfDayの時間を設定する。 Throws:std.datetime.date.DateTimeException指定された時間が 無効な TimeOfDay. - const pure nothrow @nogc @property @safe ubyte
minute
(); - 時過ぎの分。
- pure @property @safe void
minute
(intminute
); - 時過ぎの分。Parameters:
int minute
この TimeOfDay分 Throws:std.datetime.date.DateTimeExceptionもし が無効な場合は TimeOfDay. - const pure nothrow @nogc @property @safe ubyte
second
(); - 分を数秒過ぎている。
- pure @property @safe void
second
(intsecond
); - 分経過秒数。Parameters:
int second
この TimeOfDay秒に設定する。 Throws:std.datetime.date.DateTimeExceptionもし が無効な場合は TimeOfDay. - pure nothrow @nogc ref @safe TimeOfDay
roll
(string units)(longvalue
)
if (units == "hours");
pure nothrow @nogc ref @safe TimeOfDayroll
(string units)(longvalue
)
if (units == "minutes" || units == "seconds"); - に指定されたユニット数を追加する。 TimeOfDay加算する。A 負の数は引く。ローリングと加算の違いは、ローリングはより大きなユニットには影響しないということである。 大きな単位に影響しないことである。例えば TimeOfDay 例えば、1時間分の分を転がすと、まったく同じ TimeOfDay. 使用可能な単位は"hours" 、"minutes" 、"seconds" である。Parameters:
units 追加するユニット。 long value
追加するユニット数 TimeOfDay. Returns:TimeOfDay (this) への言及。Examples:auto tod1 = TimeOfDay(7, 12, 0); tod1.roll!"hours"(1); writeln(tod1); // TimeOfDay(8, 12, 0) auto tod2 = TimeOfDay(7, 12, 0); tod2.roll!"hours"(-1); writeln(tod2); // TimeOfDay(6, 12, 0) auto tod3 = TimeOfDay(23, 59, 0); tod3.roll!"minutes"(1); writeln(tod3); // TimeOfDay(23, 0, 0) auto tod4 = TimeOfDay(0, 0, 0); tod4.roll!"minutes"(-1); writeln(tod4); // TimeOfDay(0, 59, 0) auto tod5 = TimeOfDay(23, 59, 59); tod5.roll!"seconds"(1); writeln(tod5); // TimeOfDay(23, 59, 0) auto tod6 = TimeOfDay(0, 0, 0); tod6.roll!"seconds"(-1); writeln(tod6); // TimeOfDay(0, 0, 59)
- const pure nothrow @nogc @safe TimeOfDay
opBinary
(string op)(Durationduration
)
if (op == "+" || op == "-"); - を加算または減算した結果を返す。 core.time.Duration を加算または減算した結果を返す。 TimeOfDay.の算術演算の型は以下の通りである。 TimeOfDayこの演算子 は
TimeOfDay + 継続時間 --> 時間 時間 - 期間 --> 時間 Parameters:Duration duration
である。 core.time.Durationで加減する。 この TimeOfDay. Examples:import core.time : hours, minutes, seconds; writeln(TimeOfDay(12, 12, 12) + seconds(1)); // TimeOfDay(12, 12, 13) writeln(TimeOfDay(12, 12, 12) + minutes(1)); // TimeOfDay(12, 13, 12) writeln(TimeOfDay(12, 12, 12) + hours(1)); // TimeOfDay(13, 12, 12) writeln(TimeOfDay(23, 59, 59) + seconds(1)); // TimeOfDay(0, 0, 0) writeln(TimeOfDay(12, 12, 12) - seconds(1)); // TimeOfDay(12, 12, 11) writeln(TimeOfDay(12, 12, 12) - minutes(1)); // TimeOfDay(12, 11, 12) writeln(TimeOfDay(12, 12, 12) - hours(1)); // TimeOfDay(11, 12, 12) writeln(TimeOfDay(0, 0, 0) - seconds(1)); // TimeOfDay(23, 59, 59)
- pure nothrow @nogc ref @safe TimeOfDay
opOpAssign
(string op)(Durationduration
)
if (op == "+" || op == "-"); - の算術演算の合法的な型は以下のとおりである。 TimeOfDayこの演算子 は
TimeOfDay + 継続時間 --> 時間 時間 - 期間 --> 時間 Parameters:Duration duration
を core.time.Durationで加減する。 この TimeOfDay. - const pure nothrow @nogc @safe Duration
opBinary
(string op)(TimeOfDayrhs
)
if (op == "-"); - 2つの TimeOfDays.の算術演算の有効な型は以下の通りである。 TimeOfDayこの演算子 は
TimeOfDay - 曜日 --> 継続時間 Parameters:TimeOfDay rhs
この TimeOfDayをこの値から引く。 - const pure nothrow @safe string
toISOString
();
const voidtoISOString
(W)(ref Wwriter
)
if (isOutputRange!(W, char)); - Parameters:
W writer
char 出力範囲 Returns:出力レンジを使用しない場合はstring 、それ以外はvoid 。Examples:writeln(TimeOfDay(0, 0, 0).toISOString()); // "000000" writeln(TimeOfDay(12, 30, 33).toISOString()); // "123033"
- const pure nothrow @safe string
toISOExtString
();
const voidtoISOExtString
(W)(ref Wwriter
)
if (isOutputRange!(W, char)); - Parameters:
W writer
char 出力範囲 Returns:出力レンジを使用しない場合はstring 、それ以外はvoid 。Examples:writeln(TimeOfDay(0, 0, 0).toISOExtString()); // "00:00:00" writeln(TimeOfDay(12, 30, 33).toISOExtString()); // "12:30:33"
- const pure nothrow @safe string
toString
();
const voidtoString
(W)(ref Wwriter
)
if (isOutputRange!(W, char)); - TimeOfDayを文字列に変換する。への変換を簡単にするために存在する関数である。 TimeOfDayを を簡単に文字列に変換できるようにするために存在する。 を文字列に簡単に変換できるようにするために存在する。また を単純に文字列に変換する TimeOfDayを文字列に変換するのも簡単になる。 to!string 、format 、writeln など、toStringを使ってユーザー定義型を変換する関数を使う場合、aを単純に文字列に変換することも簡単になる。 のようなユーザー定義型を変換する関数を使うときにも、簡単にaを文字列に変換することができる。そのため、多くのコードで を直接呼び出すことはあまりないだろう。 文字列のフォーマットは意図的に指定されていない。 文字列の書式を気にするコードは、toISOString 、 toISOExtString やその他のカスタム書式関数を使うべきである。 などを使うべきである。その理由は コードで使用する書式が明確になるため、コードの保守や書式設定にエラーが発生しにくくなる。 コードの保守や、生成された文字列を消費する他のソフトウェアとのやり取りでエラーが発生しにくくなる。 生成された文字列を消費する他のソフトウェアとやりとりする際に、ミスが起こりにくくなる。これと同じ理由で TimeOfDayにはfromString 関数がない。 fromISOString とfromISOExtString がある。 toStringが返す書式は、将来変わるかもしれないし、変わらないかもしれない。Parameters:
W writer
char 出力範囲 Returns:出力レンジを使用しない場合はstring 、それ以外はvoid 。 - pure @safe TimeOfDay
fromISOString
(S)(scope const SisoString
)
if (isSomeString!S); - を作成する。 TimeOfDayをHHMMSS形式の文字列から作成する。 与えられた文字列から空白が取り除かれる。Parameters:
S isoString
ISO 形式で時刻をフォーマットした文字列。 Throws:std.datetime.date.DateTimeException与えられた文字列が でない場合、あるいは TimeOfDayが有効でない場合は は無効となる。 - pure @safe TimeOfDay
fromISOExtString
(S)(scope const SisoExtString
)
if (isSomeString!S); - HH:MM:SS形式の文字列から TimeOfDayを作成する。 与えられた文字列から空白が取り除かれる。Parameters:
S isoExtString
の ISO 拡張書式でフォーマットされた文字列。 倍。 Throws:std.datetime.date.DateTimeException与えられた文字列が がISO拡張形式でない場合、あるいは TimeOfDay が有効でない場合 - static pure nothrow @nogc @property @safe TimeOfDay
min
(); - 真夜中を返す。
- static pure nothrow @nogc @property @safe TimeOfDay
max
(); - 真夜中の1秒前を返す。
- pure nothrow @nogc @safe bool
valid
(string units)(intvalue
)
if (units == "months" || units == "hours" || units == "minutes" || units == "seconds"); - は、指定された値が指定された単位型で有効かどうかを返す。 を返す。当然ながら、継続時間は特定の範囲に拘束されないが の範囲でなければならない)。 1~12の範囲でなければならない)。Parameters:
units 検証する時間の単位。 int value
検証する数。 Examples:assert(valid!"hours"(12)); assert(!valid!"hours"(32)); assert(valid!"months"(12)); assert(!valid!"months"(13));
- pure nothrow @nogc @safe bool
valid
(string units)(intyear
, intmonth
, intday
)
if (units == "days"); - 指定された日が指定された年と月に有効かどうかを返す。Parameters:
units 検証する時間の単位。 int year
検証する日の年。 int month
有効化する日の月(1月は1)。 int day
検証する日 Examples:assert(valid!"days"(2016, 2, 29)); assert(!valid!"days"(2016, 2, 30)); assert(valid!"days"(2017, 2, 20)); assert(!valid!"days"(2017, 2, 29));
- pure @safe void
enforceValid
(string units)(intvalue
, stringfile
= __FILE__, size_tline
= __LINE__)
if (units == "months" || units == "hours" || units == "minutes" || units == "seconds"); - Parameters:
units 検証する時間の単位。 int value
検証する数。 string file
がスローされた場合にリストするファイル。 DateTimeExceptionがスローされた場合にリストするファイル。 size_t line
もし DateTimeExceptionがスローされた場合に をスローする。 Throws:DateTimeExceptionもし valid!units(value
)が偽の場合。Examples:import std.exception : assertThrown, assertNotThrown; assertNotThrown(enforceValid!"months"(10)); assertNotThrown(enforceValid!"seconds"(40)); assertThrown!DateTimeException(enforceValid!"months"(0)); assertThrown!DateTimeException(enforceValid!"hours"(24)); assertThrown!DateTimeException(enforceValid!"minutes"(60)); assertThrown!DateTimeException(enforceValid!"seconds"(60));
- pure @safe void
enforceValid
(string units)(intyear
, Monthmonth
, intday
, stringfile
= __FILE__, size_tline
= __LINE__)
if (units == "days"); - 日数の妥当性は、その日が属する年と月の両方に依存する。 その日が属する年と月の両方に依存するため、3つの変数すべてをとって を取る。Parameters:
units 検証する時間の単位。 int year
その日の年 Month month
検証する日の月。 int day
検証する日 string file
がスローされた場合にリストするファイル。 DateTimeExceptionがスローされた場合にリストするファイル。 size_t line
もし DateTimeExceptionがスローされた場合にリストする をスローする。 Throws:DateTimeExceptionvalid!"days"(year, month, day) がfalseの場合。Examples:import std.exception : assertThrown, assertNotThrown; assertNotThrown(enforceValid!"days"(2000, Month.jan, 1)); // 閏年 assertNotThrown(enforceValid!"days"(2000, Month.feb, 29)); assertThrown!DateTimeException(enforceValid!"days"(2001, Month.feb, 29)); assertThrown!DateTimeException(enforceValid!"days"(2000, Month.jan, 32)); assertThrown!DateTimeException(enforceValid!"days"(2000, Month.apr, 31));
- pure nothrow @nogc @safe int
daysToDayOfWeek
(DayOfWeekcurrDoW
, DayOfWeekdow
); - 現在の曜日から指定された曜日までの日数を返す。 までの日数を返す。もし同じなら、結果は0である。Parameters:
DayOfWeek currDoW
現在の曜日。 DayOfWeek dow
日数を取得する曜日。 Examples:writeln(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.mon)); // 0 writeln(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.sun)); // 6 writeln(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.wed)); // 2
- pure @safe int
monthsToMonth
(intcurrMonth
, intmonth
); - 現在の月から指定された月までの月数を返す。 までの月数を返す。もし同じなら、結果は0である。Parameters:
int currMonth
現在の月。 int month
その年の何月かを表す。 Examples:writeln(monthsToMonth(Month.jan, Month.jan)); // 0 writeln(monthsToMonth(Month.jan, Month.dec)); // 11 writeln(monthsToMonth(Month.jul, Month.oct)); // 3
- pure nothrow @nogc @safe bool
yearIsLeapYear
(intyear
); - グレゴリオ暦がうるう年かどうか。Parameters:
int year
テストされる年。 Examples:foreach (year; [1, 2, 100, 2001, 2002, 2003, 2005, 2006, 2007, 2009, 2010]) { assert(!yearIsLeapYear(year)); assert(!yearIsLeapYear(-year)); } foreach (year; [0, 4, 8, 400, 800, 1600, 1996, 2000, 2004, 2008, 2012]) { assert(yearIsLeapYear(year)); assert(yearIsLeapYear(-year)); }
- enum auto
isTimePoint
(T); - 与えられた型がタイムポイントとして機能するために必要な関数をすべて定義しているかどうか。 関数を定義しているかどうか。
- T の最小値である という静的プロパティを定義しなければならない。 の最小値である を として定義しなければならない。 min T Unqual!T
- T は、 という静的プロパティを定義しなければならない。 の最大値である という静的プロパティを定義しなければならない。 max T Unqual!T
- T を受け付ける足し算と引き算用の を定義しなければならない。 を定義しなければならない。opBinary core.time.Durationを受け取り、Unqual!T を返す。
- T 足し算と引き算のために、 を定義しなければならない。 を受け付けるopOpAssign core.time.Durationを受け取り、ref Unqual!T を返す。
- T を受け取って返す、引き算用の を定義しなければならない。 を受け取りopBinary Tcore.time.Duration.
Examples:import core.time : Duration; import std.datetime.interval : Interval; import std.datetime.systime : SysTime; static assert(isTimePoint!Date); static assert(isTimePoint!DateTime); static assert(isTimePoint!SysTime); static assert(isTimePoint!TimeOfDay); static assert(!isTimePoint!int); static assert(!isTimePoint!Duration); static assert(!isTimePoint!(Interval!SysTime));
- pure nothrow @nogc @safe bool
validTimeUnits
(string[]units
...); - 与えられた文字列がすべて有効な時間単位であるかどうか。"nsecs" は有効な時間単位とはみなされない。std.datetime ではhnsecs以上の精度を扱うことができない。 で "nsecs"を扱う関数はほとんどない。Examples:
assert(validTimeUnits("msecs", "seconds", "minutes")); assert(validTimeUnits("days", "weeks", "months")); assert(!validTimeUnits("ms", "seconds", "minutes"));
- pure @safe int
cmpTimeUnits
(stringlhs
, stringrhs
); - "years" 。 "hnsecs" は最小の単位である。Returns:
this < rhs < 0 this == rhs 0 this > rhs > 0 Throws:DateTimeException与えられた文字列のいずれかが有効な である。Examples:import std.exception : assertThrown; writeln(cmpTimeUnits("hours", "hours")); // 0 assert(cmpTimeUnits("hours", "weeks") < 0); assert(cmpTimeUnits("months", "seconds") > 0); assertThrown!DateTimeException(cmpTimeUnits("month", "second"));
- template
CmpTimeUnits
(string lhs, string rhs) if (validTimeUnits(lhs, rhs)) - コンパイル時に2つの時間単位文字列を比較する。"years" は最大の単位で、 は最小の単位である。 単位であり、"hnsecs" が最小である。このテンプレートがcmpTimeUnits の代わりに使われるのは、コンパイル時に例外を投げることができないからである。 はコンパイル時に例外をスローできず、cmpTimeUnits は与えられた文字列が有効な時間単位文字列であることを強制しなければならないからである。 を強制しなければならないからである。このテンプレートは代わりに テンプレート制約を使用する。Returns:
this < rhs < 0 this == rhs 0 this > rhs > 0 Examples:static assert(CmpTimeUnits!("years", "weeks") > 0); static assert(CmpTimeUnits!("days", "days") == 0); static assert(CmpTimeUnits!("seconds", "hours") < 0);
Copyright © 1999-2024 by the D Language Foundation
DEEPL APIにより翻訳、ところどころ修正。
このページの最新版(英語)
このページの原文(英語)
翻訳時のdmdのバージョン: 2.108.0
ドキュメントのdmdのバージョン: 2.109.1
翻訳日付 :
HTML生成日時:
編集者: dokutoku