Creates a new DateTime instance from a specific date and time.
(
cls,
year: SupportsIndex,
month: SupportsIndex,
day: SupportsIndex,
hour: SupportsIndex = 0,
minute: SupportsIndex = 0,
second: SupportsIndex = 0,
microsecond: SupportsIndex = 0,
tz: str | float | Timezone | FixedTimezone | None | datetime.tzinfo = UTC,
fold: int = 1,
raise_on_unknown_times: bool = False,
)
| 84 | |
| 85 | @classmethod |
| 86 | def create( |
| 87 | cls, |
| 88 | year: SupportsIndex, |
| 89 | month: SupportsIndex, |
| 90 | day: SupportsIndex, |
| 91 | hour: SupportsIndex = 0, |
| 92 | minute: SupportsIndex = 0, |
| 93 | second: SupportsIndex = 0, |
| 94 | microsecond: SupportsIndex = 0, |
| 95 | tz: str | float | Timezone | FixedTimezone | None | datetime.tzinfo = UTC, |
| 96 | fold: int = 1, |
| 97 | raise_on_unknown_times: bool = False, |
| 98 | ) -> Self: |
| 99 | """ |
| 100 | Creates a new DateTime instance from a specific date and time. |
| 101 | """ |
| 102 | if tz is not None: |
| 103 | tz = pendulum._safe_timezone(tz) |
| 104 | |
| 105 | dt = datetime.datetime( |
| 106 | year, month, day, hour, minute, second, microsecond, fold=fold |
| 107 | ) |
| 108 | |
| 109 | if tz is not None: |
| 110 | dt = tz.convert(dt, raise_on_unknown_times=raise_on_unknown_times) |
| 111 | |
| 112 | return cls( |
| 113 | dt.year, |
| 114 | dt.month, |
| 115 | dt.day, |
| 116 | dt.hour, |
| 117 | dt.minute, |
| 118 | dt.second, |
| 119 | dt.microsecond, |
| 120 | tzinfo=dt.tzinfo, |
| 121 | fold=dt.fold, |
| 122 | ) |
| 123 | |
| 124 | @classmethod |
| 125 | def instance( |