digitalmars.D.learn - SysTime.add!"days" missing
- Spacen Jasset (11/11) Mar 17 2014 I would like to subtract 60 days from a SysTime, but find that
- Vladimir Panteleev (5/8) Mar 17 2014 You can do this in a simpler way: t -= 60.days;
- Spacen Jasset (4/12) Mar 17 2014 Thanks. What devilish magic allows for the syntax 60.days? (how
- Adam D. Ruppe (7/9) Mar 17 2014 There's a function in core.time:
- Spacen Jasset (3/13) Mar 17 2014 Thanks Adam, is there a good explanation anywhere? It must be
- Ary Borenszweig (2/18) Mar 17 2014 http://dlang.org/function.html#pseudo-member
- Spacen Jasset (5/29) Mar 17 2014 Thanks but I still can't see how it fully explains this:
- Adam D. Ruppe (7/9) Mar 17 2014 There's a separate function days
- Spacen Jasset (2/11) Mar 17 2014 Thanks Adam, I see how the magic happens now.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/5) Mar 17 2014 Here is another one:
I would like to subtract 60 days from a SysTime, but find that SysTime.add!"days" is not available, unlike Systime.roll!"days" which is available. main.d(18): Error: template instance add!("days") add!("days") does not match te mplate declaration add(string units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes) if (units == "years" || units == "months") Why is "days" add missing? How might I get round this? Regards, Spacen.
Mar 17 2014
On Monday, 17 March 2014 at 11:11:26 UTC, Spacen Jasset wrote:I would like to subtract 60 days from a SysTime, but find that SysTime.add!"days" is not available, unlike Systime.roll!"days" which is available.You can do this in a simpler way: t -= 60.days; SysTime.add likely specializes on durations the length of which varies depending from their starting point, due to the varying number of days in a month or in a year.
Mar 17 2014
On Monday, 17 March 2014 at 11:52:08 UTC, Vladimir Panteleev wrote:On Monday, 17 March 2014 at 11:11:26 UTC, Spacen Jasset wrote:Thanks. What devilish magic allows for the syntax 60.days? (how does it work)I would like to subtract 60 days from a SysTime, but find that SysTime.add!"days" is not available, unlike Systime.roll!"days" which is available.You can do this in a simpler way: t -= 60.days; SysTime.add likely specializes on durations the length of which varies depending from their starting point, due to the varying number of days in a month or in a year.
Mar 17 2014
On Monday, 17 March 2014 at 14:31:54 UTC, Spacen Jasset wrote:Thanks. What devilish magic allows for the syntax 60.days? (how does it work)There's a function in core.time: Duration days(int n); D functions f(x, t...) can also be called x.f(t) (or x.f without parameters if there's no additional arguments). This works on all types, it is called uniform function call syntax, or UFCS. It lets us extend other things with new methods.
Mar 17 2014
On Monday, 17 March 2014 at 14:39:16 UTC, Adam D. Ruppe wrote:On Monday, 17 March 2014 at 14:31:54 UTC, Spacen Jasset wrote:Thanks Adam, is there a good explanation anywhere? It must be newish.Thanks. What devilish magic allows for the syntax 60.days? (how does it work)There's a function in core.time: Duration days(int n); D functions f(x, t...) can also be called x.f(t) (or x.f without parameters if there's no additional arguments). This works on all types, it is called uniform function call syntax, or UFCS. It lets us extend other things with new methods.
Mar 17 2014
On 3/17/14, 12:11 PM, Spacen Jasset wrote:On Monday, 17 March 2014 at 14:39:16 UTC, Adam D. Ruppe wrote:http://dlang.org/function.html#pseudo-memberOn Monday, 17 March 2014 at 14:31:54 UTC, Spacen Jasset wrote:Thanks Adam, is there a good explanation anywhere? It must be newish.Thanks. What devilish magic allows for the syntax 60.days? (how does it work)There's a function in core.time: Duration days(int n); D functions f(x, t...) can also be called x.f(t) (or x.f without parameters if there's no additional arguments). This works on all types, it is called uniform function call syntax, or UFCS. It lets us extend other things with new methods.
Mar 17 2014
On Monday, 17 March 2014 at 15:24:22 UTC, Ary Borenszweig wrote:On 3/17/14, 12:11 PM, Spacen Jasset wrote:Thanks but I still can't see how it fully explains this: writeln("60 days: ", 60.days); There is some type magic going on somewhere, because 60 is an int and days is a random method that happens to belong to Duration.On Monday, 17 March 2014 at 14:39:16 UTC, Adam D. Ruppe wrote:http://dlang.org/function.html#pseudo-memberOn Monday, 17 March 2014 at 14:31:54 UTC, Spacen Jasset wrote:Thanks Adam, is there a good explanation anywhere? It must be newish.Thanks. What devilish magic allows for the syntax 60.days? (how does it work)There's a function in core.time: Duration days(int n); D functions f(x, t...) can also be called x.f(t) (or x.f without parameters if there's no additional arguments). This works on all types, it is called uniform function call syntax, or UFCS. It lets us extend other things with new methods.
Mar 17 2014
On Monday, 17 March 2014 at 16:16:20 UTC, Spacen Jasset wrote:int and days is a random method that happens to belong to Duration.There's a separate function days https://github.com/D-Programming-Language/druntime/blob/master/src/core/time.d#L928 that one belongs to Duration https://github.com/D-Programming-Language/druntime/blob/master/src/core/time.d#L1414 this one doesn't. In the 60.days instance, it is calling the second function.
Mar 17 2014
On Monday, 17 March 2014 at 16:33:34 UTC, Adam D. Ruppe wrote:On Monday, 17 March 2014 at 16:16:20 UTC, Spacen Jasset wrote:Thanks Adam, I see how the magic happens now.int and days is a random method that happens to belong to Duration.There's a separate function days https://github.com/D-Programming-Language/druntime/blob/master/src/core/time.d#L928 that one belongs to Duration https://github.com/D-Programming-Language/druntime/blob/master/src/core/time.d#L1414 this one doesn't. In the 60.days instance, it is calling the second function.
Mar 17 2014
On 03/17/2014 08:11 AM, Spacen Jasset wrote:Thanks Adam, is there a good explanation anywhere?Here is another one: http://ddili.org/ders/d.en/ufcs.html Ali
Mar 17 2014