| 221 | } |
| 222 | |
| 223 | bool DateValue::ToYearMonthDay(int* year, int* month, int* day) const { |
| 224 | DCHECK(year != nullptr); |
| 225 | DCHECK(month != nullptr); |
| 226 | DCHECK(day != nullptr); |
| 227 | if (UNLIKELY(!IsValid())) return false; |
| 228 | |
| 229 | // Uses the same method to calculate the year as DateValue::ToYear(). |
| 230 | int tmp = days_since_epoch_ * 400 + 287811200; |
| 231 | int first_year = (tmp - 591) / 146097; |
| 232 | int last_year = (tmp + 288) / 146097; |
| 233 | |
| 234 | int jan1_dse = CalcFirstDayOfYearSinceEpoch(last_year); |
| 235 | if (jan1_dse <= days_since_epoch_) { |
| 236 | *year = last_year; |
| 237 | } else { |
| 238 | *year = first_year; |
| 239 | jan1_dse -= IsLeapYear(first_year) ? 366 : 365; |
| 240 | } |
| 241 | DCHECK(*year >= MIN_YEAR && *year <= MAX_YEAR); |
| 242 | |
| 243 | // Day of year. 0 is used for January 1. |
| 244 | int days_since_jan1 = days_since_epoch_ - jan1_dse; |
| 245 | |
| 246 | return GetMonthAndDayFromDaysSinceJan1(*year, days_since_jan1, month, day); |
| 247 | } |
| 248 | |
| 249 | int DateValue::WeekDay() const { |
| 250 | if (UNLIKELY(!IsValid())) return -1; |