@@ -89,6 +89,9 @@ public class DateTimeFunction {
8989 // 32536771199.999999, or equivalent '3001-01-18 23:59:59.999999' UTC
9090 private static final Double MYSQL_MAX_TIMESTAMP = 32536771200d ;
9191
92+ // Mode used for week/week_of_year function by default when no argument is provided
93+ private static final ExprIntegerValue DEFAULT_WEEK_OF_YEAR_MODE = new ExprIntegerValue (0 );
94+
9295 /**
9396 * Register Date and Time Functions.
9497 *
@@ -472,6 +475,9 @@ private DefaultFunctionResolver dayOfWeek(FunctionName name) {
472475 */
473476 private DefaultFunctionResolver dayOfYear (BuiltinFunctionName dayOfYear ) {
474477 return define (dayOfYear .getName (),
478+ implWithProperties (nullMissingHandlingWithProperties ((functionProperties , arg )
479+ -> DateTimeFunction .dayOfYearToday (
480+ functionProperties .getQueryStartClock ())), INTEGER , TIME ),
475481 impl (nullMissingHandling (DateTimeFunction ::exprDayOfYear ), INTEGER , DATE ),
476482 impl (nullMissingHandling (DateTimeFunction ::exprDayOfYear ), INTEGER , DATETIME ),
477483 impl (nullMissingHandling (DateTimeFunction ::exprDayOfYear ), INTEGER , TIMESTAMP ),
@@ -559,6 +565,9 @@ private DefaultFunctionResolver minute_of_day() {
559565 */
560566 private DefaultFunctionResolver month (BuiltinFunctionName month ) {
561567 return define (month .getName (),
568+ implWithProperties (nullMissingHandlingWithProperties ((functionProperties , arg )
569+ -> DateTimeFunction .monthOfYearToday (
570+ functionProperties .getQueryStartClock ())), INTEGER , TIME ),
562571 impl (nullMissingHandling (DateTimeFunction ::exprMonth ), INTEGER , DATE ),
563572 impl (nullMissingHandling (DateTimeFunction ::exprMonth ), INTEGER , DATETIME ),
564573 impl (nullMissingHandling (DateTimeFunction ::exprMonth ), INTEGER , TIMESTAMP ),
@@ -783,10 +792,18 @@ private DefaultFunctionResolver utc_timestamp() {
783792 */
784793 private DefaultFunctionResolver week (BuiltinFunctionName week ) {
785794 return define (week .getName (),
795+ implWithProperties (nullMissingHandlingWithProperties ((functionProperties , arg )
796+ -> DateTimeFunction .weekOfYearToday (
797+ DEFAULT_WEEK_OF_YEAR_MODE ,
798+ functionProperties .getQueryStartClock ())), INTEGER , TIME ),
786799 impl (nullMissingHandling (DateTimeFunction ::exprWeekWithoutMode ), INTEGER , DATE ),
787800 impl (nullMissingHandling (DateTimeFunction ::exprWeekWithoutMode ), INTEGER , DATETIME ),
788801 impl (nullMissingHandling (DateTimeFunction ::exprWeekWithoutMode ), INTEGER , TIMESTAMP ),
789802 impl (nullMissingHandling (DateTimeFunction ::exprWeekWithoutMode ), INTEGER , STRING ),
803+ implWithProperties (nullMissingHandlingWithProperties ((functionProperties , time , modeArg )
804+ -> DateTimeFunction .weekOfYearToday (
805+ modeArg ,
806+ functionProperties .getQueryStartClock ())), INTEGER , TIME , INTEGER ),
790807 impl (nullMissingHandling (DateTimeFunction ::exprWeek ), INTEGER , DATE , INTEGER ),
791808 impl (nullMissingHandling (DateTimeFunction ::exprWeek ), INTEGER , DATETIME , INTEGER ),
792809 impl (nullMissingHandling (DateTimeFunction ::exprWeek ), INTEGER , TIMESTAMP , INTEGER ),
@@ -827,6 +844,15 @@ private DefaultFunctionResolver date_format() {
827844 );
828845 }
829846
847+ private ExprValue dayOfYearToday (Clock clock ) {
848+ return new ExprIntegerValue (LocalDateTime .now (clock ).getDayOfYear ());
849+ }
850+
851+ private ExprValue weekOfYearToday (ExprValue mode , Clock clock ) {
852+ return new ExprIntegerValue (
853+ CalendarLookup .getWeekNumber (mode .integerValue (), LocalDateTime .now (clock ).toLocalDate ()));
854+ }
855+
830856 /**
831857 * Day of Week implementation for ExprValue when passing in an arguemt of type TIME.
832858 *
@@ -1519,6 +1545,10 @@ private ExprValue exprYear(ExprValue date) {
15191545 return new ExprIntegerValue (date .dateValue ().getYear ());
15201546 }
15211547
1548+ private ExprValue monthOfYearToday (Clock clock ) {
1549+ return new ExprIntegerValue (LocalDateTime .now (clock ).getMonthValue ());
1550+ }
1551+
15221552 private LocalDateTime formatNow (Clock clock ) {
15231553 return formatNow (clock , 0 );
15241554 }
0 commit comments