Date issues

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Date issues

Lee Sylvester
Hey List,

Does anyone know a good way to find the difference between two dates?
Getting the days, hours and minutes between each would be great. At the
moment, I'm doing this in neko :

var milliseconds = currentTime.getTime() - previousTime.time.getTime();

but this causes the method it exists in to return prematurely. I don't
think Neko likes it much, though I don't know why;
previousTime.getTime() definitely returns a smaller value than that of
currentTime.

Anyway, any help would be greatly appreciated. What I'd idealy like to
do is :

compare( date1 : Date, date2 : Date ) : { days : Int, hours : Int,
minutes : Int, seconds : Int, milliseconds : Float };

:-)

Thanks,
Lee


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Date issues

Lee Sylvester
It seems that Date.getTime() is flawed. If I do :

var date : Date = Date.now();
var mills : Float = date.getTime();

the application halts at the second line and doesn't proceed.

Any ideas?

Lee



Lee McColl Sylvester wrote:

> Hey List,
>
> Does anyone know a good way to find the difference between two dates?
> Getting the days, hours and minutes between each would be great. At
> the moment, I'm doing this in neko :
>
> var milliseconds = currentTime.getTime() - previousTime.time.getTime();
>
> but this causes the method it exists in to return prematurely. I don't
> think Neko likes it much, though I don't know why;
> previousTime.getTime() definitely returns a smaller value than that of
> currentTime.
>
> Anyway, any help would be greatly appreciated. What I'd idealy like to
> do is :
>
> compare( date1 : Date, date2 : Date ) : { days : Int, hours : Int,
> minutes : Int, seconds : Int, milliseconds : Float };
>
> :-)
>
> Thanks,
> Lee
>
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Date issues

Lee Sylvester
Actually, that route below does work. However, if you are using a date
retrieved from a SPOD object, it doesn't. :-(

Lee



Lee McColl Sylvester wrote:

> It seems that Date.getTime() is flawed. If I do :
>
> var date : Date = Date.now();
> var mills : Float = date.getTime();
>
> the application halts at the second line and doesn't proceed.
>
> Any ideas?
>
> Lee
>
>
>
> Lee McColl Sylvester wrote:
>> Hey List,
>>
>> Does anyone know a good way to find the difference between two dates?
>> Getting the days, hours and minutes between each would be great. At
>> the moment, I'm doing this in neko :
>>
>> var milliseconds = currentTime.getTime() - previousTime.time.getTime();
>>
>> but this causes the method it exists in to return prematurely. I
>> don't think Neko likes it much, though I don't know why;
>> previousTime.getTime() definitely returns a smaller value than that
>> of currentTime.
>>
>> Anyway, any help would be greatly appreciated. What I'd idealy like
>> to do is :
>>
>> compare( date1 : Date, date2 : Date ) : { days : Int, hours : Int,
>> minutes : Int, seconds : Int, milliseconds : Float };
>>
>> :-)
>>
>> Thanks,
>> Lee
>>
>>
>
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Date issues

Lee Sylvester
Okay, this is weird. I have a field in a SPOD object that is of type
date. If I print it to the console, it shows the records date, like this :

2008-11-14 10:18:21

Also, if I print its type, it shows as a Date object, as expected...
However, it isn't a Date object. The only way I can use the data, is to
first do this :

spodObject.time = Date.fromString( Std.string( spodObject.time ) );

Then it works.

Lee




Lee McColl Sylvester wrote:

> Actually, that route below does work. However, if you are using a date
> retrieved from a SPOD object, it doesn't. :-(
>
> Lee
>
>
>
> Lee McColl Sylvester wrote:
>> It seems that Date.getTime() is flawed. If I do :
>>
>> var date : Date = Date.now();
>> var mills : Float = date.getTime();
>>
>> the application halts at the second line and doesn't proceed.
>>
>> Any ideas?
>>
>> Lee
>>
>>
>>
>> Lee McColl Sylvester wrote:
>>> Hey List,
>>>
>>> Does anyone know a good way to find the difference between two
>>> dates? Getting the days, hours and minutes between each would be
>>> great. At the moment, I'm doing this in neko :
>>>
>>> var milliseconds = currentTime.getTime() - previousTime.time.getTime();
>>>
>>> but this causes the method it exists in to return prematurely. I
>>> don't think Neko likes it much, though I don't know why;
>>> previousTime.getTime() definitely returns a smaller value than that
>>> of currentTime.
>>>
>>> Anyway, any help would be greatly appreciated. What I'd idealy like
>>> to do is :
>>>
>>> compare( date1 : Date, date2 : Date ) : { days : Int, hours : Int,
>>> minutes : Int, seconds : Int, milliseconds : Float };
>>>
>>> :-)
>>>
>>> Thanks,
>>> Lee
>>>
>>>
>>
>>
>
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Date issues

Nicolas Cannasse
Lee McColl Sylvester a écrit :

> Okay, this is weird. I have a field in a SPOD object that is of type
> date. If I print it to the console, it shows the records date, like this :
>
> 2008-11-14 10:18:21
>
> Also, if I print its type, it shows as a Date object, as expected...
> However, it isn't a Date object. The only way I can use the data, is to
> first do this :
>
> spodObject.time = Date.fromString( Std.string( spodObject.time ) );
>
> Then it works.

Try trace(Type.typeof(spodObject.time)); to check if your time is indeed
converted to Date by SPOD.

If you're using SQLite, I think there is no native support for the Date
type.

In all cases, you should get an exception.

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Date issues

Lee Sylvester
Hey Nicolas,

It returns as :

TClass({ __name__ => [String], __construct__ => #function:1, prototype
=> { indexOf => #function:2, __class__ => ..., __add => #function:1,
__radd => #function:1, split => #function:1, __compare => #function:1,
lastIndexOf .... etc. etc. etc.

My guess is it's a string ;-)

Isn't there a way the SPOD can check that it's coming from Sqlite and
cast it to a Date accordingly?

Thanks,
Lee




Nicolas Cannasse wrote:

> Lee McColl Sylvester a écrit :
>> Okay, this is weird. I have a field in a SPOD object that is of type
>> date. If I print it to the console, it shows the records date, like
>> this :
>>
>> 2008-11-14 10:18:21
>>
>> Also, if I print its type, it shows as a Date object, as expected...
>> However, it isn't a Date object. The only way I can use the data, is
>> to first do this :
>>
>> spodObject.time = Date.fromString( Std.string( spodObject.time ) );
>>
>> Then it works.
>
> Try trace(Type.typeof(spodObject.time)); to check if your time is
> indeed converted to Date by SPOD.
>
> If you're using SQLite, I think there is no native support for the
> Date type.
>
> In all cases, you should get an exception.
>
> Best,
> Nicolas
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Date issues

Nicolas Cannasse
Lee McColl Sylvester a écrit :

> Hey Nicolas,
>
> It returns as :
>
> TClass({ __name__ => [String], __construct__ => #function:1, prototype
> => { indexOf => #function:2, __class__ => ..., __add => #function:1,
> __radd => #function:1, split => #function:1, __compare => #function:1,
> lastIndexOf .... etc. etc. etc.
>
> My guess is it's a string ;-)
>
> Isn't there a way the SPOD can check that it's coming from Sqlite and
> cast it to a Date accordingly?

No, because it doesn't know that you want it to be a Date. The problem
is that there is no DATE type at runtime in SQLite (!)

One possibility is to use "make/unmake" methods of the Manager to
perform String->Date conversion.

Nicolas

--
haXe - an open source web programming language
http://haxe.org