Re: [Vala] Time in vala



On Tue, Dec 2, 2008 at 10:06 AM, Karl Lattimer <karl qdh org uk> wrote:
I can never find enough documentation about time in vala :( so I'm going
to ask a bunch of questions here... Maybe I'll add a GNOME live page
when I've got the important stuff done... God knows I already want to
update the GTK/Cairo stuff to be more detailed.

Anyway.

I need to turn a timestamp into a string, but I can't seem to see how to
do this... Something like

int timestamp = "1234151912"; // whatever...
var time = new Time;
string date_string = Time.strftime("%s", timestamp);
// an output like yyyy-mm-dd hh:mm would be nice..

I can never seem to read the time vapi stuff properly :/

A little introduction to using the features of time would be really
nice, I've got to do a whole load of calculations e.g. convert a
timestamp to a nearest month, day, hour etc... then build a scale of
various months/days/hours near by... I need to convert things back and
forth between timestamps and do things like add one day and get the
timestamp for that etc...


strftime() looks like strftime(char *str, size_t maxsize, const char
*fmt, struct tm *time) so I would assume you'd use it something like

//you can initialize this from a time_t, but i'm cheating for the sake of email
var timeval = Time();
timeval.minute = 1;
timeval.hour = 15;

//string needs some allocated room, because strftime() is expecting a
char[] + len and not char*
// and char[80] doesn't seem to work at last check. so I'm cheating again.
string date_string = "                                  ";
timeval.strftime (date_string, "%I:%M");
//do something with date_string;

I may be missing a cast or something (emailware), but I think that's
how it'd work. However, it seems really awkward that strftime() is
bound like that, as it's not at all what a Vala programmer would
expect. May just be an artifact of ongoing work for getting arrays
working right though.

Maybe Vala should ship a new Time() class that makes this less awkward
to work with? And/or we could scream at the GLib guys to make a new
(portable) GTime class for GLib 3.0... Maybe you could hack something
around GDate for your needs?

-A. Walton

BR,
 K

_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]