digitalmars.D.learn - DateTime.opBinary
- bachmeier (6/6) Nov 29 2015 I was just reading through the documentation for std.datetime.
- anonymous (18/24) Nov 29 2015 You can add a Duration to a DateTime, giving you a new DateTime. And you...
- bachmeier (2/20) Nov 29 2015 Thanks. I'll add these as examples.
- Chris Wright (7/15) Nov 29 2015 Duration is defined in core.time: https://dlang.org/phobos/
- bachmeier (10/16) Nov 29 2015 Yeah, there has to be a better way to document these functions. I
- Jonathan M Davis via Digitalmars-d-learn (6/10) Nov 30 2015 Once TickDuration finally goes away, then functions like DateTime's opBi...
- Chris Wright (4/20) Nov 30 2015 Or with explicit overloads, which would be easier to document and easier...
I was just reading through the documentation for std.datetime. DateTime.opBinary looks pretty interesting: Does anyone know how to use it? You certainly can't learn anything from the documentation, because duration is a mystery. If someone knows, I can submit a PR with that information added.
Nov 29 2015
On 30.11.2015 00:25, bachmeier wrote:I was just reading through the documentation for std.datetime. DateTime.opBinary looks pretty interesting: Does anyone know how to use it? You certainly can't learn anything from the documentation, because duration is a mystery. If someone knows, I can submit a PR with that information added.You can add a Duration to a DateTime, giving you a new DateTime. And you can subtract a DateTime from another, giving you the Duration between them. Example: ---- import std.datetime, std.stdio; void main() { DateTime oldYear = DateTime(2015, 12, 31, 23, 59, 59); writeln(oldYear); /* 2015-Dec-31 23:59:59 */ DateTime newYear = oldYear + 1.seconds; /* adding Duration to DateTime */ writeln(newYear); /* 2016-Jan-01 00:00:00 */ Duration diff = newYear - oldYear; /* subtracting DateTime from DateTime */ writeln(diff); /* 1 sec */ } ----
Nov 29 2015
On Sunday, 29 November 2015 at 23:52:05 UTC, anonymous wrote:You can add a Duration to a DateTime, giving you a new DateTime. And you can subtract a DateTime from another, giving you the Duration between them. Example: ---- import std.datetime, std.stdio; void main() { DateTime oldYear = DateTime(2015, 12, 31, 23, 59, 59); writeln(oldYear); /* 2015-Dec-31 23:59:59 */ DateTime newYear = oldYear + 1.seconds; /* adding Duration to DateTime */ writeln(newYear); /* 2016-Jan-01 00:00:00 */ Duration diff = newYear - oldYear; /* subtracting DateTime from DateTime */ writeln(diff); /* 1 sec */ } ----Thanks. I'll add these as examples.
Nov 29 2015
On Sun, 29 Nov 2015 23:25:14 +0000, bachmeier wrote:I was just reading through the documentation for std.datetime. DateTime.opBinary looks pretty interesting: Does anyone know how to use it? You certainly can't learn anything from the documentation, because duration is a mystery. If someone knows, I can submit a PR with that information added.Duration is defined in core.time: https://dlang.org/phobos/ core_time.html#Duration Unfortunately, ddoc doesn't automatically cross-reference these for you, which results in confusion. (As if it weren't confusing enough to have everything wrapped in templates with filters rather than simply using const(Duration).)
Nov 29 2015
On Sunday, 29 November 2015 at 23:53:41 UTC, Chris Wright wrote:Duration is defined in core.time: https://dlang.org/phobos/ core_time.html#Duration Unfortunately, ddoc doesn't automatically cross-reference these for you, which results in confusion. (As if it weren't confusing enough to have everything wrapped in templates with filters rather than simply using const(Duration).)Yeah, there has to be a better way to document these functions. I guess I could have figured out that there is a Duration struct from this opBinary(string op, D)(in D duration) if ((op == "+" || op == "-") && (is(Unqual!D == Duration) || is(Unqual!D == TickDuration))) but (string op, D) -> (in D duration) -> is(Unqual!D == Duration) is something that would be rejected from Boost because it's too complicated for C++.
Nov 29 2015
On Sunday, November 29, 2015 23:53:41 Chris Wright via Digitalmars-d-learn wrote:Unfortunately, ddoc doesn't automatically cross-reference these for you, which results in confusion. (As if it weren't confusing enough to have everything wrapped in templates with filters rather than simply using const(Duration).)Once TickDuration finally goes away, then functions like DateTime's opBinary can be simplified to just take Duration. But until TickDuration and the few things that use it in their API have gone through the deprecation process, we're stuck with it in places like this. - Jonathan M Davis
Nov 30 2015
On Mon, 30 Nov 2015 01:30:28 -0800, Jonathan M Davis via Digitalmars-d-learn wrote:On Sunday, November 29, 2015 23:53:41 Chris Wright via Digitalmars-d-learn wrote:Or with explicit overloads, which would be easier to document and easier to read and as easy to maintain.Unfortunately, ddoc doesn't automatically cross-reference these for you, which results in confusion. (As if it weren't confusing enough to have everything wrapped in templates with filters rather than simply using const(Duration).)Once TickDuration finally goes away, then functions like DateTime's opBinary can be simplified to just take Duration. But until TickDuration and the few things that use it in their API have gone through the deprecation process, we're stuck with it in places like this. - Jonathan M Davis
Nov 30 2015