_datetimemodule.c.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(datetime_date_fromtimestamp__doc__,
  9. "fromtimestamp($type, timestamp, /)\n"
  10. "--\n"
  11. "\n"
  12. "Create a date from a POSIX timestamp.\n"
  13. "\n"
  14. "The timestamp is a number, e.g. created via time.time(), that is interpreted\n"
  15. "as local time.");
  16. #define DATETIME_DATE_FROMTIMESTAMP_METHODDEF \
  17. {"fromtimestamp", (PyCFunction)datetime_date_fromtimestamp, METH_O|METH_CLASS, datetime_date_fromtimestamp__doc__},
  18. static PyObject *
  19. iso_calendar_date_new_impl(PyTypeObject *type, int year, int week,
  20. int weekday);
  21. static PyObject *
  22. iso_calendar_date_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  23. {
  24. PyObject *return_value = NULL;
  25. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  26. #define NUM_KEYWORDS 3
  27. static struct {
  28. PyGC_Head _this_is_not_used;
  29. PyObject_VAR_HEAD
  30. PyObject *ob_item[NUM_KEYWORDS];
  31. } _kwtuple = {
  32. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  33. .ob_item = { &_Py_ID(year), &_Py_ID(week), &_Py_ID(weekday), },
  34. };
  35. #undef NUM_KEYWORDS
  36. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  37. #else // !Py_BUILD_CORE
  38. # define KWTUPLE NULL
  39. #endif // !Py_BUILD_CORE
  40. static const char * const _keywords[] = {"year", "week", "weekday", NULL};
  41. static _PyArg_Parser _parser = {
  42. .keywords = _keywords,
  43. .fname = "IsoCalendarDate",
  44. .kwtuple = KWTUPLE,
  45. };
  46. #undef KWTUPLE
  47. PyObject *argsbuf[3];
  48. PyObject * const *fastargs;
  49. Py_ssize_t nargs = PyTuple_GET_SIZE(args);
  50. int year;
  51. int week;
  52. int weekday;
  53. fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 3, 3, 0, argsbuf);
  54. if (!fastargs) {
  55. goto exit;
  56. }
  57. year = _PyLong_AsInt(fastargs[0]);
  58. if (year == -1 && PyErr_Occurred()) {
  59. goto exit;
  60. }
  61. week = _PyLong_AsInt(fastargs[1]);
  62. if (week == -1 && PyErr_Occurred()) {
  63. goto exit;
  64. }
  65. weekday = _PyLong_AsInt(fastargs[2]);
  66. if (weekday == -1 && PyErr_Occurred()) {
  67. goto exit;
  68. }
  69. return_value = iso_calendar_date_new_impl(type, year, week, weekday);
  70. exit:
  71. return return_value;
  72. }
  73. PyDoc_STRVAR(datetime_datetime_now__doc__,
  74. "now($type, /, tz=None)\n"
  75. "--\n"
  76. "\n"
  77. "Returns new datetime object representing current time local to tz.\n"
  78. "\n"
  79. " tz\n"
  80. " Timezone object.\n"
  81. "\n"
  82. "If no tz is specified, uses local timezone.");
  83. #define DATETIME_DATETIME_NOW_METHODDEF \
  84. {"now", _PyCFunction_CAST(datetime_datetime_now), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_now__doc__},
  85. static PyObject *
  86. datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz);
  87. static PyObject *
  88. datetime_datetime_now(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  89. {
  90. PyObject *return_value = NULL;
  91. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  92. #define NUM_KEYWORDS 1
  93. static struct {
  94. PyGC_Head _this_is_not_used;
  95. PyObject_VAR_HEAD
  96. PyObject *ob_item[NUM_KEYWORDS];
  97. } _kwtuple = {
  98. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  99. .ob_item = { &_Py_ID(tz), },
  100. };
  101. #undef NUM_KEYWORDS
  102. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  103. #else // !Py_BUILD_CORE
  104. # define KWTUPLE NULL
  105. #endif // !Py_BUILD_CORE
  106. static const char * const _keywords[] = {"tz", NULL};
  107. static _PyArg_Parser _parser = {
  108. .keywords = _keywords,
  109. .fname = "now",
  110. .kwtuple = KWTUPLE,
  111. };
  112. #undef KWTUPLE
  113. PyObject *argsbuf[1];
  114. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  115. PyObject *tz = Py_None;
  116. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  117. if (!args) {
  118. goto exit;
  119. }
  120. if (!noptargs) {
  121. goto skip_optional_pos;
  122. }
  123. tz = args[0];
  124. skip_optional_pos:
  125. return_value = datetime_datetime_now_impl(type, tz);
  126. exit:
  127. return return_value;
  128. }
  129. /*[clinic end generated code: output=42654669940e0e3a input=a9049054013a1b77]*/