MCPcopy Create free account
hub / github.com/apache/arrow / get_days_from_date

Function get_days_from_date

python/pyarrow/src/arrow/python/datetime.cc:104–155  ·  view source on GitHub ↗

Calculates the days offset from the 1970 epoch.

Source from the content-addressed store, hash-verified

102
103// Calculates the days offset from the 1970 epoch.
104static int64_t get_days_from_date(int64_t date_year, int64_t date_month,
105 int64_t date_day) {
106 int64_t i, month;
107 int64_t year, days = 0;
108 int64_t* month_lengths;
109
110 year = date_year - 1970;
111 days = year * 365;
112
113 // Adjust for leap years
114 if (days >= 0) {
115 // 1968 is the closest leap year before 1970.
116 // Exclude the current year, so add 1.
117 year += 1;
118 // Add one day for each 4 years
119 days += year / 4;
120 // 1900 is the closest previous year divisible by 100
121 year += 68;
122 // Subtract one day for each 100 years
123 days -= year / 100;
124 // 1600 is the closest previous year divisible by 400
125 year += 300;
126 // Add one day for each 400 years
127 days += year / 400;
128 } else {
129 // 1972 is the closest later year after 1970.
130 // Include the current year, so subtract 2.
131 year -= 2;
132 // Subtract one day for each 4 years
133 days += year / 4;
134 // 2000 is the closest later year divisible by 100
135 year -= 28;
136 // Add one day for each 100 years
137 days -= year / 100;
138 // 2000 is also the closest later year divisible by 400
139 // Subtract one day for each 400 years
140 days += year / 400;
141 }
142
143 month_lengths = _days_per_month_table[is_leapyear(date_year)];
144 month = date_month - 1;
145
146 // Add the months
147 for (i = 0; i < month; ++i) {
148 days += month_lengths[i];
149 }
150
151 // Add the days
152 days += date_day - 1;
153
154 return days;
155}
156
157// Modifies '*days_' to be the day offset within the year,
158// and returns the year.

Callers 1

PyDate_to_daysFunction · 0.85

Calls 1

is_leapyearFunction · 0.85

Tested by

no test coverage detected