digitalmars.D.learn - How to add time to Clock.currTime
- JohnnyK (10/10) Oct 04 2013 Hi All,
- Brad Anderson (4/15) Oct 04 2013 auto t = Clock.currTime;
- Brad Anderson (12/27) Oct 04 2013 And just a little bit more info, another way to write this is:
- JohnnyK (4/32) Oct 04 2013 Wow I appreciate the quick response. Ok I have seen this before.
- Jesse Phillips (5/10) Oct 04 2013 http://dlang.org/phobos/core_time.html#.dur
- Jonathan M Davis (20/23) Oct 04 2013 dur is in core.time as are the aliases for each of the units:
- JohnnyK (5/39) Oct 07 2013 I appreciate everyone's responses and yes Jonathan that article
Hi All, I did search but I cannot find it anywhere. All I want to do is add 300 seconds to the output of Clock.currTime. So basically if Clock.currTime equals 2013-Oct-04 17:19:31.3338333 then I want to subtract 300 seconds from that to get the time that it was 300 seconds ago. In other languages I would convert the time value to seconds and subtract the 300 seconds then convert it back to what ever time value it was before. I don't know how to convert 300 seconds to hnsecs and I have never actually heard of hnsecs before. Anyway if someone could help I would appreciate it.
Oct 04 2013
On Friday, 4 October 2013 at 21:46:43 UTC, JohnnyK wrote:Hi All, I did search but I cannot find it anywhere. All I want to do is add 300 seconds to the output of Clock.currTime. So basically if Clock.currTime equals 2013-Oct-04 17:19:31.3338333 then I want to subtract 300 seconds from that to get the time that it was 300 seconds ago. In other languages I would convert the time value to seconds and subtract the 300 seconds then convert it back to what ever time value it was before. I don't know how to convert 300 seconds to hnsecs and I have never actually heard of hnsecs before. Anyway if someone could help I would appreciate it.auto t = Clock.currTime; t -= 300.seconds; t += 300.seconds;
Oct 04 2013
On Friday, 4 October 2013 at 21:50:31 UTC, Brad Anderson wrote:On Friday, 4 October 2013 at 21:46:43 UTC, JohnnyK wrote:And just a little bit more info, another way to write this is: auto t = Clock.currTime; t -= seconds(300); t += seconds(300); The first way I wrote is just the UFCS version of that. You could also do: auto t = Clock.currTime; t -= dur!"seconds"(300); t += dur!"seconds"(300); seconds() is just an alias for the dur template with the "seconds" template argument.Hi All, I did search but I cannot find it anywhere. All I want to do is add 300 seconds to the output of Clock.currTime. So basically if Clock.currTime equals 2013-Oct-04 17:19:31.3338333 then I want to subtract 300 seconds from that to get the time that it was 300 seconds ago. In other languages I would convert the time value to seconds and subtract the 300 seconds then convert it back to what ever time value it was before. I don't know how to convert 300 seconds to hnsecs and I have never actually heard of hnsecs before. Anyway if someone could help I would appreciate it.auto t = Clock.currTime; t -= 300.seconds; t += 300.seconds;
Oct 04 2013
On Friday, 4 October 2013 at 21:54:19 UTC, Brad Anderson wrote:On Friday, 4 October 2013 at 21:50:31 UTC, Brad Anderson wrote:Wow I appreciate the quick response. Ok I have seen this before. What is the dur? Where is dur defined? Also I am confused how 300.seconds would work. How can a literal number have properties?On Friday, 4 October 2013 at 21:46:43 UTC, JohnnyK wrote:And just a little bit more info, another way to write this is: auto t = Clock.currTime; t -= seconds(300); t += seconds(300); The first way I wrote is just the UFCS version of that. You could also do: auto t = Clock.currTime; t -= dur!"seconds"(300); t += dur!"seconds"(300); seconds() is just an alias for the dur template with the "seconds" template argument.Hi All, I did search but I cannot find it anywhere. All I want to do is add 300 seconds to the output of Clock.currTime. So basically if Clock.currTime equals 2013-Oct-04 17:19:31.3338333 then I want to subtract 300 seconds from that to get the time that it was 300 seconds ago. In other languages I would convert the time value to seconds and subtract the 300 seconds then convert it back to what ever time value it was before. I don't know how to convert 300 seconds to hnsecs and I have never actually heard of hnsecs before. Anyway if someone could help I would appreciate it.auto t = Clock.currTime; t -= 300.seconds; t += 300.seconds;
Oct 04 2013
On Saturday, 5 October 2013 at 01:31:35 UTC, JohnnyK wrote:Wow I appreciate the quick response. Ok I have seen this before. What is the dur? Where is dur defined? Also I am confused how 300.seconds would work. How can a literal number have properties?300.seconds is using UFCS (Uniform Function Call Syntax) since int does not have a property "seconds" the compiler will rewrite the call to seconds(300).
Oct 04 2013
On Saturday, October 05, 2013 03:31:33 JohnnyK wrote:Wow I appreciate the quick response. Ok I have seen this before. What is the dur? Where is dur defined? Also I am confused how 300.seconds would work. How can a literal number have properties?dur is in core.time as are the aliases for each of the units: http://dlang.org/phobos/core_time.html#dur 300.seconds works thanks to UFCS (Universal Function Call Syntax). Any time that the compiler sees x.foo(args); and foo is not a member function of x, it converts it to foo(x, args); So, if there's a free function with that name which will work with those arguments, then it will be called (otherwise, you'll get an error, because there is no matching function). The parens can be dropped on 300.seconds, because the parens are optional on function calls that take no arguments. seconds is not actually a property function (it's an alias for dur!"seconds, which is not a property function either), but the fact that the parens are optional makes it so that you can use it with the same syntax that would be used for a getter property. If you want an overview of std.datetime and the time stuff in Phobos, I suggest that you read http://dlang.org/intro-to-datetime.html - Jonathan M Davis
Oct 04 2013
On Saturday, 5 October 2013 at 02:42:49 UTC, Jonathan M Davis wrote:On Saturday, October 05, 2013 03:31:33 JohnnyK wrote:I appreciate everyone's responses and yes Jonathan that article did help. I know I looked under the article section but I must have overlooked this article.Wow I appreciate the quick response. Ok I have seen this before. What is the dur? Where is dur defined? Also I am confused how 300.seconds would work. How can a literal number have properties?dur is in core.time as are the aliases for each of the units: http://dlang.org/phobos/core_time.html#dur 300.seconds works thanks to UFCS (Universal Function Call Syntax). Any time that the compiler sees x.foo(args); and foo is not a member function of x, it converts it to foo(x, args); So, if there's a free function with that name which will work with those arguments, then it will be called (otherwise, you'll get an error, because there is no matching function). The parens can be dropped on 300.seconds, because the parens are optional on function calls that take no arguments. seconds is not actually a property function (it's an alias for dur!"seconds, which is not a property function either), but the fact that the parens are optional makes it so that you can use it with the same syntax that would be used for a getter property. If you want an overview of std.datetime and the time stuff in Phobos, I suggest that you read http://dlang.org/intro-to-datetime.html - Jonathan M Davis
Oct 07 2013