about dateTime data

158 views
Skip to first unread message

Annalisa Minelli

unread,
Jan 26, 2015, 8:15:14 AM1/26/15
to gama-p...@googlegroups.com
Hi all,
I'm trying to obtain a list of timestamps between a starting and ending time with a granularity of 10minutes.
While how to define a 'timestep' (so, the length of a cycle) is quite clear, since I have to add to a list a serie of timestamps, I'd like to know if there's a data type 'dateTime' or 'timestamp' in order to manage this kind of data not manually.

I mean: I would like that when I say to my algorithm "add 10 minutes to the current date time" - and it's 23h58 of 28th February, and it's bissextile.. it gives me in output automatically 00h08 of 29th February and things like that.
Something of just "formatted" as datetime and rattached to the universal managing of date/time.

Moreover I saw the action 'getCurrentDateTime' of SQLSKILL but if I try to get this information it tells me that it 'Couldn't resolve reference to VarDefinition 'dateFormat'.'

this is my lino of code:
string<string> ctime <- string<string> (self getCurrentDateTime(dateFormat: 'yyyy-MM-dd HH:mm:ss'));

where I get wrong?

Many thanks,
Annalisa

Patrick Taillandier

unread,
Jan 27, 2015, 2:08:34 AM1/27/15
to gama-p...@googlegroups.com
Hi,

For the moment, as far as I know, there is no direct way to manage this kind of calendar. The "built-in" calendar of GAMA does not take into account bissextile years and consider a duration of 31 days for all the months).

So you have three solutions:
   - develop a new plug-in in Java with operators allowing to manage the universal time/date (we already included in GAMA a library that can allow to do that quite easily).
  - in your GAMA model, add new variables (day, month, year...) to manage that by manually (with a reflex and many tests)
  - generate a CSV file with all the necessary data with another software (directly with Python ?) and read the file with GAMA.

No idea concerning the "getCurrentDateTime" operator that I have never used ;) . Maybe Thai will be able to answer you.

Cheers,

Patrick

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Jason Barto

unread,
Jan 27, 2015, 7:06:20 AM1/27/15
to gama-p...@googlegroups.com
Annalisa,
I had to do a similar activity which was constrained by days and created a simple implementation based on the C library gmttime.  It's crude but you may find it helpful for use in your model.  The GAML file provides functions for translation of a unix timestamp (number of seconds since 1 Jan 1970) to a GMT date and time string.  Hopefully you'll find it helpful.

Sincerely,
Jason
Timeclock.gaml

Thai Truong Minh

unread,
Jan 27, 2015, 11:57:51 AM1/27/15
to gama-p...@googlegroups.com
Hi Annalisa,

You can get the current time of system by use function getCurrentDateTime of  SQLSKILL 

string currenttime <- self getCurrentDateTime(dateFormat::'yyyy-MM-dd HH:mm:ss');

or in shorter way
string currenttime <- self getCurrentDateTime('yyyy-MM-dd HH:mm:ss');

Add 10 day to current time:

string nday <-self getDateOffset ('yyyy-MM-dd HH:mm:ss', currenttime, 10);
write "add ten days" + nday;

Cheers,
Truong Minh Thai

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.



--
TRUONG Minh Thai
Doctorant

IRIT
Université Toulouse 1 Capitole
2, rue du Doyen Gabriel Marty
31 042 Toulouse Cedex 9. France

email: thai.tr...@gmail.com
phone: 06 49 70 7057


Annalisa Minelli

unread,
Jan 28, 2015, 5:16:21 AM1/28/15
to gama-p...@googlegroups.com
Thank you Thai,
these are the exact commands I'd need..
so it seems that maybe there's no need to implement any addictional plugin to treat 'datetime', am I wrong?

the only thing is that, in my script, the command 'getCurrentdateTime' is not recognised by GAMA which tells me 'unknown action or operator'
even if I ask this action to be executed by an agent with skills [SQLSKILL]:



//into the init of global..
init {
create connector;
ask connector {
string currenttime <- self getCurrentDateTime(dateFormat::'yyyy-MM-dd HH:mm:ss');
...
}

//agent type definition:
species connector skills:[SQLSKILL] {
// todo
}



where I get wrong?

Many thanks,
Annalisa

Annalisa Minelli

unread,
Jan 28, 2015, 5:37:17 AM1/28/15
to gama-p...@googlegroups.com
Absolutely a good job Jason!

..but maybe for my work are sufficient the two functions of Thai - if I will be able to use them :-)

thanks at anyway,
Annalisa

Thai Truong Minh

unread,
Jan 28, 2015, 8:39:38 AM1/28/15
to gama-p...@googlegroups.com
Hi Annalisa,

Which version did you use? release version or developer version?

I think that getCurrentDateTime is only supported in developer version.
If you used developer version then you update package irit.gaml.extensions.database

I attached an example of using getCurrentDateTime

Cheers,
Truong Minh Thai
DateTimeTest.gaml

Thai Truong Minh

unread,
Jan 28, 2015, 3:41:24 PM1/28/15
to gama-p...@googlegroups.com
Hi Annalisa,

There is another solution for date and time.
That you can use current_time, current_timestamp ... of postgres in select query
For example:

write "current date:" + self select [params:: POSTGRES, select:: "SELECT current_date as cdate "];
write "current time:" + self select [params:: POSTGRES, select:: "SELECT current_time as ctime "];
write "current timesamp:" + self select [params:: POSTGRES, select:: "SELECT current_timestamp as ctimestamp "];
write "current date + 10 days:" + self select [params:: POSTGRES, select:: "SELECT (current_date + integer '10') as ndate "];
write "current timesamp + 10 days:" + self select [params:: POSTGRES, select:: "SELECT (current_timestamp + interval '10 days') as ntimestamp "];
write "current timesamp + 10 hours:" + self select [params:: POSTGRES, select:: "SELECT (current_timestamp + interval '10 hours') as ntimestamp "];

Note: You can read other functions in this link (http://www.postgresql.org/docs/8.2/static/functions-datetime.html)

I attach the example model  for postgres and you can do that in the same way with SQLSERVER, MySQL ...

Cheers,
Truong Minh Thai
DateTimePostgres.gaml

Annalisa Minelli

unread,
Jan 29, 2015, 5:32:44 AM1/29/15
to gama-p...@googlegroups.com
Hi Thai,
I compiled the dev version and now the functions are correctly recognised, exactly as you told me. Thanks.

Effectively it is a good idea to use the postgresql functions you suggest me, since I have to add, sometimes, very short "time delta" (just like 10minutes).
At anyway, it seems to me not so fool, in order to use less dependencies than the possible, thinking about implementing other functions to manage datetime data directly in GAMA, in addition to the two functions you already wrote.

Since I don't know java at all :-) yes, for sure I can do it (as Patrick suggested), but I need a little bit of time and supervision..
eventually do you agree to help me doing this?

Many thanks,
Annalisa

Thai Truong Minh

unread,
Jan 29, 2015, 7:00:03 AM1/29/15
to gama-p...@googlegroups.com
Hi Annalisa,

Yes, of course.
You are always welcome!

Cheers,
Truong Minh Thai
Reply all
Reply to author
Forward
0 new messages