www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Setting dates

reply "Joel" <joelcnz gmail.com> writes:
I've been trying to set a date for my program (a small struct):

import std.datetime;

auto date = cast(DateTime)Clock.currTime();
setDate(date.day, date.month, date.year);

Problem is that day & month are not integers. And date.day.to!int 
doesn't work either.
Jul 10 2014
parent reply Jonathan M Davis via Digitalmars-d-learn writes:
On Friday, July 11, 2014 04:01:24 Joel via Digitalmars-d-learn wrote:
 I've been trying to set a date for my program (a small struct):

 import std.datetime;

 auto date = cast(DateTime)Clock.currTime();
 setDate(date.day, date.month, date.year);

 Problem is that day & month are not integers. And date.day.to!int
 doesn't work either.
You're going to need to provid more details. SetDate is not a standard function, so it must be yours, and we don't know anything about it - not even its signature, which makes it awfully hard to help you. That being said, date.day returns ubyte, date.month returns std.datetime.Month, and date.year returns ushort, all of which implicitly convert to int. So, I don't see why you would be having an problems converting them to int. This compiles just fine int year = date.year; int month = date.month; int day = date.day; And date.day.to!int or date.day.to!int() both compile just fine as long as you import std.conv. But calling to!int() is completely unnecessary, because the conversion is implicit, as show above. So, without more details, we can't help you. - Jonathan M Davis
Jul 13 2014
parent "Joel" <joelcnz gmail.com> writes:
On Monday, 14 July 2014 at 05:58:13 UTC, Jonathan M Davis via 
Digitalmars-d-learn wrote:
 On Friday, July 11, 2014 04:01:24 Joel via Digitalmars-d-learn 
 wrote:
 I've been trying to set a date for my program (a small struct):

 import std.datetime;

 auto date = cast(DateTime)Clock.currTime();
 setDate(date.day, date.month, date.year);

 Problem is that day & month are not integers. And 
 date.day.to!int
 doesn't work either.
You're going to need to provid more details. SetDate is not a standard function, so it must be yours, and we don't know anything about it - not even its signature, which makes it awfully hard to help you. That being said, date.day returns ubyte, date.month returns std.datetime.Month, and date.year returns ushort, all of which implicitly convert to int. So, I don't see why you would be having an problems converting them to int. This compiles just fine int year = date.year; int month = date.month; int day = date.day; And date.day.to!int or date.day.to!int() both compile just fine as long as you import std.conv. But calling to!int() is completely unnecessary, because the conversion is implicit, as show above. So, without more details, we can't help you. - Jonathan M Davis
Thanks for the reply, Jonathan. I think I've got it working now.
Jul 16 2014