~ubuntu-branches/ubuntu/saucy/geary/saucy-updates

« back to all changes in this revision

Viewing changes to src/engine/util/util-time.vala

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2013-10-10 17:40:37 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20131010174037-5p5o4dlsoewek2kg
Tags: 0.4.0-0ubuntu1
New stable version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2013 Yorba Foundation
 
2
 *
 
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.
 
5
 */
 
6
 
 
7
namespace Geary.Time {
 
8
 
 
9
/**
 
10
 * Converts a DateTime object into the nearest approximation of time_t.
 
11
 *
 
12
 * Since DateTime can store down to the microsecond and dates before UNIX epoch, there's some
 
13
 * truncating going on here.
 
14
 */
 
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;
 
26
    
 
27
    return tm.mktime();
 
28
}
 
29
 
 
30
}