MCPcopy Index your code
hub / github.com/python-pendulum/pendulum / local_time

Function local_time

src/pendulum/_helpers.py:92–158  ·  view source on GitHub ↗

Returns a UNIX time as a broken-down time for a particular transition type.

(
    unix_time: int, utc_offset: int, microseconds: int
)

Source from the content-addressed store, hash-verified

90
91
92def local_time(
93 unix_time: int, utc_offset: int, microseconds: int
94) -> tuple[int, int, int, int, int, int, int]:
95 """
96 Returns a UNIX time as a broken-down time
97 for a particular transition type.
98 """
99 year = EPOCH_YEAR
100 seconds = math.floor(unix_time)
101
102 # Shift to a base year that is 400-year aligned.
103 if seconds >= 0:
104 seconds -= 10957 * SECS_PER_DAY
105 year += 30 # == 2000
106 else:
107 seconds += (146097 - 10957) * SECS_PER_DAY
108 year -= 370 # == 1600
109
110 seconds += utc_offset
111
112 # Handle years in chunks of 400/100/4/1
113 year += 400 * (seconds // SECS_PER_400_YEARS)
114 seconds %= SECS_PER_400_YEARS
115 if seconds < 0:
116 seconds += SECS_PER_400_YEARS
117 year -= 400
118
119 leap_year = 1 # 4-century aligned
120
121 sec_per_100years = SECS_PER_100_YEARS[leap_year]
122 while seconds >= sec_per_100years:
123 seconds -= sec_per_100years
124 year += 100
125 leap_year = 0 # 1-century, non 4-century aligned
126 sec_per_100years = SECS_PER_100_YEARS[leap_year]
127
128 sec_per_4years = SECS_PER_4_YEARS[leap_year]
129 while seconds >= sec_per_4years:
130 seconds -= sec_per_4years
131 year += 4
132 leap_year = 1 # 4-year, non century aligned
133 sec_per_4years = SECS_PER_4_YEARS[leap_year]
134
135 sec_per_year = SECS_PER_YEAR[leap_year]
136 while seconds >= sec_per_year:
137 seconds -= sec_per_year
138 year += 1
139 leap_year = 0 # non 4-year aligned
140 sec_per_year = SECS_PER_YEAR[leap_year]
141
142 # Handle months and days
143 month = TM_DECEMBER + 1
144 day = seconds // SECS_PER_DAY + 1
145 seconds %= SECS_PER_DAY
146 while month != TM_JANUARY + 1:
147 month_offset = MONTHS_OFFSETS[leap_year][month]
148 if day > month_offset:
149 day -= month_offset

Callers 3

_check_parsedMethod · 0.90

Calls

no outgoing calls

Tested by 2

Used in the wild real call sites across dependent graphs

searching dependent graphs…