Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,20 @@ public static Expression nextDay(DateV2Literal date, StringLiteral day) {
return date.plusDays(daysToAdd);
}

/**
* date arithmetic function previous_day
*/
@ExecFunction(name = "previous_day")
public static Expression previousDay(DateV2Literal date, StringLiteral day) {
int dayOfWeek = getDayOfWeek(day.getValue());
if (dayOfWeek == 0) {
throw new RuntimeException("Invalid day of week: " + day.getValue());
}
int daysToSub = (date.getDayOfWeek() - dayOfWeek + 7) % 7;
daysToSub = daysToSub == 0 ? 7 : daysToSub;
return date.plusDays(-daysToSub);
}

/**
* date transform function sec_to_time
*/
Expand Down
Loading