www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Adding days to std.datetime.Date

reply Piotr Szturmaj <bncrbme jadamspam.pl> writes:
Is it possible to add a particular number of days to a Date?

I have number of days since 1 Jan 2000 and I want to convert it to Date:

int days = read!int; // number of days since 1 Jan 2000
Date x = Date(2000, 1, 1);
x.add!"days"(days);

Unfortunately add() does not support adding days. Will it be possible in 
the future or is there another approach?

Thanks
Apr 07 2011
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 07 Apr 2011 15:07:02 -0400, Piotr Szturmaj <bncrbme jadamspam.pl>  
wrote:

 Is it possible to add a particular number of days to a Date?

 I have number of days since 1 Jan 2000 and I want to convert it to Date:

 int days = read!int; // number of days since 1 Jan 2000
 Date x = Date(2000, 1, 1);
 x.add!"days"(days);

 Unfortunately add() does not support adding days. Will it be possible in  
 the future or is there another approach?

Yes, use core.time.Duration. Duration was moved to core so it could be used in core functions, like Thread.sleep. so x += dur!"days"(days); See: http://www.digitalmars.com/d/2.0/phobos/core_time.html#dur -Steve
Apr 07 2011
parent Piotr Szturmaj <bncrbme jadamspam.pl> writes:
Steven Schveighoffer wrote:
 On Thu, 07 Apr 2011 15:07:02 -0400, Piotr Szturmaj
 <bncrbme jadamspam.pl> wrote:

 Is it possible to add a particular number of days to a Date?

 I have number of days since 1 Jan 2000 and I want to convert it to Date:

 int days = read!int; // number of days since 1 Jan 2000
 Date x = Date(2000, 1, 1);
 x.add!"days"(days);

 Unfortunately add() does not support adding days. Will it be possible
 in the future or is there another approach?

Yes, use core.time.Duration. Duration was moved to core so it could be used in core functions, like Thread.sleep. so x += dur!"days"(days); See: http://www.digitalmars.com/d/2.0/phobos/core_time.html#dur

Well, I did find it few mins ago. But std.datetime's doc still states that it provide types to represent durations of time.
 -Steve

Thanks!
Apr 07 2011