annotate Modules/_time.c @ 74135:9c19df6c8ea0 3.2

News entry for Issue12798
author Senthil Kumaran <senthil@uthcode.com>
date Fri, 23 Dec 2011 11:11:21 +0800
parents e5f5008fd56d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
62364
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
1 #include "Python.h"
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
2 #include "_time.h"
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
3
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
4 /* Exposed in timefuncs.h. */
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
5 time_t
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
6 _PyTime_DoubleToTimet(double x)
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
7 {
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
8 time_t result;
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
9 double diff;
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
10
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
11 result = (time_t)x;
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
12 /* How much info did we lose? time_t may be an integral or
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
13 * floating type, and we don't know which. If it's integral,
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
14 * we don't know whether C truncates, rounds, returns the floor,
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
15 * etc. If we lost a second or more, the C rounding is
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
16 * unreasonable, or the input just doesn't fit in a time_t;
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
17 * call it an error regardless. Note that the original cast to
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
18 * time_t can cause a C error too, but nothing we can do to
62396
e5f5008fd56d Fixed a typo in a comment.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 62364
diff changeset
19 * work around that.
62364
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
20 */
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
21 diff = x - (double)result;
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
22 if (diff <= -1.0 || diff >= 1.0) {
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
23 PyErr_SetString(PyExc_ValueError,
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
24 "timestamp out of range for platform time_t");
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
25 result = (time_t)-1;
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
26 }
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
27 return result;
6d3b05a429b5 Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
28 }