www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - tiny std.datetime question

reply n00b <n00b nospam.com> writes:
Hello, I'm kinda ashamed to ask that here, but std.datetime 
documentation is so complex... I only want to get hour/minute from a 
t_time (no timezone).
I'm moving to D2, the equivalent code in D1 was:

std.date.Date date;
date.parse(std.date.toUTCString(time));
date.hour;
Jan 16 2013
next sibling parent reply n00b <n00b nospam.com> writes:
Nevermind, found it myself.
SysTime* sys = new SysTime(standardTime, UTC());
sys.hour;



Le 16/01/2013 08:07, n00b a ťcrit :
 Hello, I'm kinda ashamed to ask that here, but std.datetime
 documentation is so complex... I only want to get hour/minute from a
 t_time (no timezone).
 I'm moving to D2, the equivalent code in D1 was:

 std.date.Date date;
 date.parse(std.date.toUTCString(time));
 date.hour;
Jan 16 2013
next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Wednesday, January 16, 2013 09:15:39 n00b wrote:
 Nevermind, found it myself.
 SysTime* sys =3D new SysTime(standardTime, UTC());
 sys.hour;
=20
 Le 16/01/2013 08:07, n00b a =C3=A9crit :
 Hello, I'm kinda ashamed to ask that here, but std.datetime
 documentation is so complex... I only want to get hour/minute from =
a
 t_time (no timezone).
 I'm moving to D2, the equivalent code in D1 was:
=20
 std.date.Date date;
 date.parse(std.date.toUTCString(time));
 date.hour;
Do you mean time_t (I've never heard of t_time)? You'll need to call=20= unixTimeToStdTime on a time_t if you want to pass it to SysTime's const= ructor.=20 And if you need to be careful of time_t if you're on Windows, because=20= Microsoft screwed it up (for some bizarre reason, they apply DST to tim= e_t -=20 DST in the _local_ time zone - making it so that the offset between the= local=20 time and time_t is always the same instead of making time_t UTC like it= 's=20 supposed to be). std.datetime assumes that you're dealing with a true t= ime_t=20 which is in UTC if you give it a time_t. Also, if you haven't already, = you=20 should read this article on std.datetime: http://dlang.org/intro-to-datetime.html - Jonathan m Davis
Jan 16 2013
parent n00b <n00b nospam.com> writes:
Le 16/01/2013 10:54, Jonathan M Davis a écrit :
 On Wednesday, January 16, 2013 09:15:39 n00b wrote:
 Nevermind, found it myself.
 SysTime* sys = new SysTime(standardTime, UTC());
 sys.hour;

 Le 16/01/2013 08:07, n00b a écrit :
 Hello, I'm kinda ashamed to ask that here, but std.datetime
 documentation is so complex... I only want to get hour/minute from a
 t_time (no timezone).
 I'm moving to D2, the equivalent code in D1 was:

 std.date.Date date;
 date.parse(std.date.toUTCString(time));
 date.hour;
Do you mean time_t (I've never heard of t_time)? You'll need to call unixTimeToStdTime on a time_t if you want to pass it to SysTime's constructor. And if you need to be careful of time_t if you're on Windows, because Microsoft screwed it up (for some bizarre reason, they apply DST to time_t - DST in the _local_ time zone - making it so that the offset between the local time and time_t is always the same instead of making time_t UTC like it's supposed to be). std.datetime assumes that you're dealing with a true time_t which is in UTC if you give it a time_t. Also, if you haven't already, you should read this article on std.datetime: http://dlang.org/intro-to-datetime.html - Jonathan m Davis
Thanks a lot for that information! ( and yes I meant time_t )
Jan 16 2013
prev sibling parent "Minas Mina" <minas_mina1990 hotmail.co.uk> writes:
On Wednesday, 16 January 2013 at 14:15:46 UTC, n00b wrote:
 Nevermind, found it myself.
 SysTime* sys = new SysTime(standardTime, UTC());
 sys.hour;



 Le 16/01/2013 08:07, n00b a écrit :
 Hello, I'm kinda ashamed to ask that here, but std.datetime
 documentation is so complex... I only want to get hour/minute 
 from a
 t_time (no timezone).
 I'm moving to D2, the equivalent code in D1 was:

 std.date.Date date;
 date.parse(std.date.toUTCString(time));
 date.hour;
This is a better way, that doesn't allocate memory: auto clock = Clock.currTime(); writeln(clock.hour); :)
Jan 16 2013
prev sibling parent reply "Rob T" <alanb ucora.com> writes:
On Wednesday, 16 January 2013 at 13:07:48 UTC, n00b wrote:
 Hello, I'm kinda ashamed to ask that here, but std.datetime 
 documentation is so complex...
You'll likely have a much easier time reading this. http://vibed.org/temp/d-programming-language.org/phobos/std/datetime.html Those pages are experimental upgrades to the current documentation generator. The docs should be a complete duplicate of the library documentation in here, it's just formatted a lot better. I hope we'll see this soon in here. --rt
Jan 16 2013
parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Thursday, January 17, 2013 07:15:14 Rob T wrote:
 On Wednesday, 16 January 2013 at 13:07:48 UTC, n00b wrote:
 Hello, I'm kinda ashamed to ask that here, but std.datetime
 documentation is so complex...
You'll likely have a much easier time reading this. http://vibed.org/temp/d-programming-language.org/phobos/std/datetime.html Those pages are experimental upgrades to the current documentation generator. The docs should be a complete duplicate of the library documentation in here, it's just formatted a lot better. I hope we'll see this soon in here.
std.datetime is pretty much the poster child for why the current format for the official documentation needs to be fixed. What's there really isn't all that complicated, and it's well-documented, but it's just too hard to sift through it all when all you have other than reading the entire page is a bunch of unorganized, near useless links at the top. - Jonathan M Davis
Jan 16 2013
parent reply "Rob T" <alanb ucora.com> writes:
On Thursday, 17 January 2013 at 06:26:21 UTC, Jonathan M Davis 
wrote:
 On Thursday, January 17, 2013 07:15:14 Rob T wrote:
 On Wednesday, 16 January 2013 at 13:07:48 UTC, n00b wrote:
 Hello, I'm kinda ashamed to ask that here, but std.datetime
 documentation is so complex...
You'll likely have a much easier time reading this. http://vibed.org/temp/d-programming-language.org/phobos/std/datetime.html Those pages are experimental upgrades to the current documentation generator. The docs should be a complete duplicate of the library documentation in here, it's just formatted a lot better. I hope we'll see this soon in here.
std.datetime is pretty much the poster child for why the current format for the official documentation needs to be fixed. What's there really isn't all that complicated, and it's well-documented, but it's just too hard to sift through it all when all you have other than reading the entire page is a bunch of unorganized, near useless links at the top. - Jonathan M Davis
Yeah, I was amazed at how much simpler things became after better formatting and organization was applied. Beforehand people were asking for std.datetime to be broken up, but no need anymore, although maybe the part on benchmarking and related (eg stopwatch) should be moved to its own module because those parts don't seem to really belong in there. I hope the effort to move to the new format has not been stalled, as I have not seen much about it in a while. Do you know what the status is? --rt
Jan 16 2013
parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Thursday, January 17, 2013 07:57:51 Rob T wrote:
 Yeah, I was amazed at how much simpler things became after better
 formatting and organization was applied. Beforehand people were
 asking for std.datetime to be broken up, but no need anymore,
 although maybe the part on benchmarking and related (eg
 stopwatch) should be moved to its own module because those parts
 don't seem to really belong in there.
I'd still like to break it up a bit, but I'm not going to do it unless some variant of DIP15 or DIP16 is implemented so that it can be done without breaking any code. So, it probably won't be broken up any time soon. It's not a big an issue though when the documentation is broken up.
 I hope the effort to move to the new format has not been stalled,
 as I have not seen much about it in a while. Do you know what the
 status is?
No idea. Andrei was pushing for various changes to the vibe stuff before actually changing the official docs, and some work was done on that, but I don't know where it stands now. Everything I know about it is from the thread where it was being discussed a few weeks ago. - Jonathan M Davis
Jan 16 2013
parent "Rob T" <alanb ucora.com> writes:
On Thursday, 17 January 2013 at 07:17:57 UTC, Jonathan M Davis 
wrote:
 I'd still like to break it up a bit, but I'm not going to do it 
 unless some
 variant of DIP15 or DIP16 is implemented so that it can be done 
 without
 breaking any code. So, it probably won't be broken up any time 
 soon. It's not
 a big an issue though when the documentation is broken up.
Yes, a complex module or multi-feature module could just have the docs broken up into separate sections, however those DIPs you mention look to me like they are definitely worth implementing. There's a lot of value being able to structure and organize your code better. --rt
Jan 17 2013