1
/* Copyright 2013 Yorba Foundation
3
* This software is licensed under the GNU Lesser General Public License
4
* (version 2.1 or later). See the COPYING file in this distribution.
10
* Converts a DateTime object into the nearest approximation of time_t.
12
* Since DateTime can store down to the microsecond and dates before UNIX epoch, there's some
13
* truncating going on here.
15
public time_t datetime_to_time_t(DateTime datetime) {
16
GLib.Time tm = GLib.Time();
17
tm.second = datetime.get_second();
18
tm.minute = datetime.get_minute();
19
tm.hour = datetime.get_hour();
20
tm.day = datetime.get_day_of_month();
21
// month is 1-based in DateTime
22
tm.month = Numeric.int_floor(datetime.get_month() - 1, 0);
23
// Time's year is number of years after 1900
24
tm.year = Numeric.int_floor(datetime.get_year() - 1900, 1900);
25
tm.isdst = datetime.is_daylight_savings() ? 1 : 0;