DateTime 物件
*************

"datetime" 模組提供各種日期和時間物件。在使用任何這些函式之前，必須將
標頭檔 "datetime.h" 引入於原始碼中（請注意，"Python.h" 並無引入該標頭
檔），且巨集 "PyDateTime_IMPORT" 必須被叫用，而這通常作為模組初始化函
式的一部分。該巨集將指向 C 結構的指標放入靜態變數 "PyDateTimeAPI" 中，
該變數會被以下巨集使用。

PyDateTime_IMPORT()

   引入 datetime C API。

   成功時填充 (populate) "PyDateTimeAPI" 指標。失敗時將
   "PyDateTimeAPI" 設為 "NULL" 並設定一個例外。呼叫者必須透過
   "PyErr_Occurred()" 檢查是否發生錯誤：

      PyDateTime_IMPORT;
      if (PyErr_Occurred()) { /* cleanup */ }

   警告:

     這和子直譯器 (subinterpreters) 不相容。

type PyDateTime_CAPI

   包含 datetime C API 欄位的結構。

   此結構的欄位為私有且可能會變動。

   不要直接使用這個；請改用 "PyDateTime_*" API。

PyDateTime_CAPI *PyDateTimeAPI

   動態配置的物件，包含 datetime C API。

   此變數僅在 "PyDateTime_IMPORT" 成功後可用。

type PyDateTime_Date

   此 "PyObject" 子型別代表 Python date 物件

type PyDateTime_DateTime

   此 "PyObject" 子型別代表 Python datetime 物件

type PyDateTime_Time

   此 "PyObject" 子型別代表 Python time 物件

type PyDateTime_Delta

   此 "PyObject" 子型別代表兩個 datetime 物件的差值

PyTypeObject PyDateTime_DateType

   此 "PyTypeObject" 實例代表 Python date 型別，與 Python layer 中的
   "datetime.date" 是同一物件

PyTypeObject PyDateTime_DateTimeType

   此 "PyTypeObject" 實例代表 Python datetime 型別，與 Python layer 中
   的 "datetime.datetime" 是同一物件

PyTypeObject PyDateTime_TimeType

   此 "PyTypeObject" 實例代表 Python time 型別，與 Python layer 中的
   "datetime.time" 是同一物件

PyTypeObject PyDateTime_DeltaType

   此 "PyTypeObject" 實例代表 Python 兩個 datetime 物件的型別，與
   Python layer 中的 "datetime.timedelta" 是同一物件

PyTypeObject PyDateTime_TZInfoType

   此 "PyTypeObject" 實例代表 Python 時區資訊型別，與 Python layer 中
   的 "datetime.tzinfo" 是同一物件

用於存取 UTC 單例 (singleton) 的巨集：

PyObject *PyDateTime_TimeZone_UTC

   回傳表示 UTC 的時區單例，是與 "datetime.timezone.utc" 相同的物件。

   在 3.7 版被加入.

型別檢查巨集：

int PyDate_Check(PyObject *ob)

   如果 *ob* 的型別為 "PyDateTime_DateType" 或 "PyDateTime_DateType"
   的子型別，則回傳 true。 *ob* 不得為 "NULL"。這個函式一定會執行成功
   。

int PyDate_CheckExact(PyObject *ob)

   如果 *ob* 的型別為 "PyDateTime_DateType"，則回傳 true。 *ob* 不得為
   "NULL"。這個函式一定會執行成功。

int PyDateTime_Check(PyObject *ob)

   如果 *ob* 的型別為 "PyDateTime_DateTimeType" 或
   "PyDateTime_DateTimeType" 的子型別，則回傳 true。*ob* 不得為 "NULL"
   。這個函式一定會執行成功。

int PyDateTime_CheckExact(PyObject *ob)

   如果 *ob* 的型別為 "PyDateTime_DateTimeType"，則回傳 true。*ob* 不
   得為 "NULL"。這個函式一定會執行成功。

int PyTime_Check(PyObject *ob)

   如果 *ob* 的型別為 "PyDateTime_TimeType" 或 "PyDateTime_TimeType"
   的子型別，則回傳 true。*ob* 不得為 "NULL"。這個函式一定會執行成功。

int PyTime_CheckExact(PyObject *ob)

   如果 *ob* 的型別為 "PyDateTime_TimeType"，則回傳 true。*ob* 不得為
   "NULL"。這個函式一定會執行成功。

int PyDelta_Check(PyObject *ob)

   如果 *ob* 的型別為 "PyDateTime_DeltaType" 或 "PyDateTime_DeltaType"
   的子型別，則回傳 true。*ob* 不得為 "NULL"。這個函式一定會執行成功。

int PyDelta_CheckExact(PyObject *ob)

   如果 *ob* 的型別為 "PyDateTime_DeltaType"，則回傳 true。*ob* 不得為
   "NULL"。這個函式一定會執行成功。

int PyTZInfo_Check(PyObject *ob)

   如果 *ob* 的型別為 "PyDateTime_TZInfoType" 或
   "PyDateTime_TZInfoType" 的子型別，則回傳 true。*ob* 不得為 "NULL"。
   這個函式一定會執行成功。

int PyTZInfo_CheckExact(PyObject *ob)

   如果 *ob* 的型別為 "PyDateTime_TZInfoType"，則回傳 true。 *ob* 不得
   為 "NULL"。這個函式一定會執行成功。

建立物件的巨集：

PyObject *PyDate_FromDate(int year, int month, int day)
    *回傳值：新的參照。*

   回傳一個有特定年、月、日的物件 "datetime.date"。

PyObject *PyDateTime_FromDateAndTime(int year, int month, int day, int hour, int minute, int second, int usecond)
    *回傳值：新的參照。*

   回傳一個有特定年、月、日、時、分、秒、微秒的物件
   "datetime.datetime"。

PyObject *PyDateTime_FromDateAndTimeAndFold(int year, int month, int day, int hour, int minute, int second, int usecond, int fold)
    *回傳值：新的參照。*

   回傳一個有特定年、月、日、時、分、秒、微秒與 fold（時間折疊）的物件
   "datetime.datetime"。

   在 3.6 版被加入.

PyObject *PyTime_FromTime(int hour, int minute, int second, int usecond)
    *回傳值：新的參照。*

   回傳一個有特定時、分、秒、微秒的物件 "datetime.time"。

PyObject *PyTime_FromTimeAndFold(int hour, int minute, int second, int usecond, int fold)
    *回傳值：新的參照。*

   回傳一個有特定時、分、秒、微秒與 fold（時間折疊）的物件
   "datetime.time"。

   在 3.6 版被加入.

PyObject *PyDelta_FromDSU(int days, int seconds, int useconds)
    *回傳值：新的參照。*

   回傳一個 "datetime.timedelta" 物件，表示給定的天數、秒數和微秒數。
   執行標準化 (normalization) 以便生成的微秒數和秒數位於
   "datetime.timedelta" 物件記錄的範圍內。

PyObject *PyTimeZone_FromOffset(PyObject *offset)
    *回傳值：新的參照。*

   回傳一個 "datetime.timezone" 物件，其未命名的固定偏移量由 *offset*
   引數表示。

   在 3.7 版被加入.

PyObject *PyTimeZone_FromOffsetAndName(PyObject *offset, PyObject *name)
    *回傳值：新的參照。*

   回傳一個 "datetime.timezone" 物件，其固定偏移量由 *offset* 引數表示
   ，並帶有 tzname *name*。

   在 3.7 版被加入.

從 date 物件中提取欄位的巨集。引數必須是個 "PyDateTime_Date" 的實例，
包括子類別（例如 "PyDateTime_DateTime"）。引數不得為 "NULL"，並且不會
檢查型別：

int PyDateTime_GET_YEAR(PyDateTime_Date *o)

   回傳年份，為正整數。

int PyDateTime_GET_MONTH(PyDateTime_Date *o)

   回傳月份，為正整數，從 1 到 12。

int PyDateTime_GET_DAY(PyDateTime_Date *o)

   回傳日期，為正整數，從 1 到 31。

從 datetime 物件中提取欄位的巨集。引數必須是個 "PyDateTime_DateTime"
的實例，包括子類別。引數不得為 "NULL"，並且不會檢查型別：

int PyDateTime_DATE_GET_HOUR(PyDateTime_DateTime *o)

   回傳小時，為正整數，從 0 到 23。

int PyDateTime_DATE_GET_MINUTE(PyDateTime_DateTime *o)

   回傳分鐘，為正整數，從 0 到 59。

int PyDateTime_DATE_GET_SECOND(PyDateTime_DateTime *o)

   回傳秒，為正整數，從0 到59。

int PyDateTime_DATE_GET_MICROSECOND(PyDateTime_DateTime *o)

   回傳微秒，為正整數，從 0 到 999999。

int PyDateTime_DATE_GET_FOLD(PyDateTime_DateTime *o)

   回傳 fold，為 0 或 1 的正整數。

   在 3.6 版被加入.

PyObject *PyDateTime_DATE_GET_TZINFO(PyDateTime_DateTime *o)

   回傳 tzinfo（可能是 "None"）。

   在 3.10 版被加入.

從 time 物件中提取欄位的巨集。引數必須是個 "PyDateTime_Time" 的實例，
包括子類別。引數不得為 "NULL"，並且不會檢查型別：

int PyDateTime_TIME_GET_HOUR(PyDateTime_Time *o)

   回傳小時，為正整數，從 0 到 23。

int PyDateTime_TIME_GET_MINUTE(PyDateTime_Time *o)

   回傳分鐘，為正整數，從 0 到 59。

int PyDateTime_TIME_GET_SECOND(PyDateTime_Time *o)

   回傳秒，為正整數，從0 到59。

int PyDateTime_TIME_GET_MICROSECOND(PyDateTime_Time *o)

   回傳微秒，為正整數，從 0 到 999999。

int PyDateTime_TIME_GET_FOLD(PyDateTime_Time *o)

   回傳 fold，為 0 或 1 的正整數。

   在 3.6 版被加入.

PyObject *PyDateTime_TIME_GET_TZINFO(PyDateTime_Time *o)

   回傳 tzinfo（可能是 "None"）。

   在 3.10 版被加入.

從 time delta 物件中提取欄位的巨集。引數必須是個 "PyDateTime_Delta" 的
實例，包括子類別。引數不能為 "NULL"，並且不會檢查型別：

int PyDateTime_DELTA_GET_DAYS(PyDateTime_Delta *o)

   以 -999999999 到 999999999 之間的整數形式回傳天數。

   在 3.3 版被加入.

int PyDateTime_DELTA_GET_SECONDS(PyDateTime_Delta *o)

   以 0 到 86399 之間的整數形式回傳秒數。

   在 3.3 版被加入.

int PyDateTime_DELTA_GET_MICROSECONDS(PyDateTime_Delta *o)

   以 0 到 999999 之間的整數形式回傳微秒數。

   在 3.3 版被加入.

為了方便模組實作 DB API 的巨集：

PyObject *PyDateTime_FromTimestamp(PyObject *args)
    *回傳值：新的參照。*

   給定一個適合傳遞給 "datetime.datetime.fromtimestamp()" 的引數元組，
   建立並回傳一個新的 "datetime.datetime" 物件。

PyObject *PyDate_FromTimestamp(PyObject *args)
    *回傳值：新的參照。*

   給定一個適合傳遞給 "datetime.date.fromtimestamp()" 的引數元組，建立
   並回傳一個新的 "datetime.date" 物件。


內部資料
********

以下符號由 C API 公開，但應視為僅供內部使用。

PyDateTime_CAPSULE_NAME

   傳遞給 "PyCapsule_Import()" 的 datetime capsule 名稱。

   僅供內部使用。請改用 "PyDateTime_IMPORT"。
