Skip to content

Commit 7d6385f

Browse files
committed
The function of month and day return an error value
1 parent 25b4f41 commit 7d6385f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,14 +603,19 @@ object DateTimeUtils {
603603
*/
604604
private[this] def getYearAndDayInYear(daysSince1970: SQLDate): (Int, Int) = {
605605
// add the difference (in days) between 1.1.1970 and the artificial year 0 (-17999)
606-
val daysNormalized = daysSince1970 + toYearZero
606+
var daysSince1970Tmp = daysSince1970
607+
// In history,the period(5.10.1582 ~ 14.10.1582) is not exist
608+
// (4.10.1582) -141428 days since 1.1.1970
609+
if (daysSince1970 <= -141428) {
610+
daysSince1970Tmp -= 10
611+
}
612+
val daysNormalized = daysSince1970Tmp + toYearZero
607613
val numOfQuarterCenturies = daysNormalized / daysIn400Years
608614
val daysInThis400 = daysNormalized % daysIn400Years + 1
609615
val (years, dayInYear) = numYears(daysInThis400)
610616
val year: Int = (2001 - 20000) + 400 * numOfQuarterCenturies + years
611617
(year, dayInYear)
612618
}
613-
614619
/**
615620
* Returns the 'day in year' value for the given date. The date is expressed in days
616621
* since 1.1.1970.

0 commit comments

Comments
 (0)