From acaecb60d141493706c7f3d19a0d45d62d5a4dcd Mon Sep 17 00:00:00 2001 From: Tao Wang <18234030530@163.com> Date: Mon, 12 Jan 2026 11:59:19 +0800 Subject: [PATCH] [fix][runtime] Fixed the bug of date_format --- .../expr/runtime/utils/DateTimeUtils.java | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/runtime/src/main/java/io/dingodb/expr/runtime/utils/DateTimeUtils.java b/runtime/src/main/java/io/dingodb/expr/runtime/utils/DateTimeUtils.java index f6680fd5..77c721e0 100644 --- a/runtime/src/main/java/io/dingodb/expr/runtime/utils/DateTimeUtils.java +++ b/runtime/src/main/java/io/dingodb/expr/runtime/utils/DateTimeUtils.java @@ -320,9 +320,28 @@ public static long fromSecond(long second) { Integer isoYear = zonedDateTime.get(IsoFields.WEEK_BASED_YEAR); format = format.replace("x", isoYear.toString()); } + if (format.contains("X")) { + Integer isoYear = zonedDateTime.get(IsoFields.WEEK_BASED_YEAR); + format = format.replace("X", isoYear.toString()); + } if (format.contains("v")) { Integer isoWeek = zonedDateTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); - format = format.replace("v", isoWeek.toString()); + if (isoWeek >= 10) { + format = format.replace("v", isoWeek.toString()); + } else { + String isoWeekStr = "0" + isoWeek; + format = format.replace("v", isoWeekStr); + } + } + if (format.contains("V")) { + Integer isoWeek = zonedDateTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); + if (isoWeek >= 10) { + format = format.replace("V", isoWeek.toString()); + } else { + String isoWeekStr = "0" + isoWeek; + format = format.replace("V", isoWeekStr); + + } } if (format.contains("'y'")) { format = format.replace("'y'", "yy"); @@ -367,9 +386,27 @@ public static String xy(Date value, String format) { Integer isoYear = localDateTime.get(IsoFields.WEEK_BASED_YEAR); format = format.replace("x", isoYear.toString()); } + if (format.contains("X")) { + Integer isoYear = localDateTime.get(IsoFields.WEEK_BASED_YEAR); + format = format.replace("X", isoYear.toString()); + } if (format.contains("v")) { Integer isoWeek = localDateTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); - format = format.replace("v", isoWeek.toString()); + if (isoWeek >= 10) { + format = format.replace("v", isoWeek.toString()); + } else { + String isoWeekStr = "0" + isoWeek; + format = format.replace("v", isoWeekStr); + } + } + if (format.contains("V")) { + Integer isoWeek = localDateTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); + if (isoWeek >= 10) { + format = format.replace("V", isoWeek.toString()); + } else { + String isoWeekStr = "0" + isoWeek; + format = format.replace("V", isoWeekStr); + } } if (format.contains("'y'")) { format = format.replace("'y'", "yy");