Skip to content

Commit 271c879

Browse files
guojn1githubgxll
authored andcommitted
[fix][runtime] Fixed the bug of date_format
1 parent 443822a commit 271c879

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

runtime/src/main/java/io/dingodb/expr/runtime/utils/DateTimeUtils.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,27 @@ public static long fromSecond(long second) {
320320
Integer isoYear = zonedDateTime.get(IsoFields.WEEK_BASED_YEAR);
321321
format = format.replace("x", isoYear.toString());
322322
}
323+
if (format.contains("X")) {
324+
Integer isoYear = zonedDateTime.get(IsoFields.WEEK_BASED_YEAR);
325+
format = format.replace("X", isoYear.toString());
326+
}
323327
if (format.contains("v")) {
324328
Integer isoWeek = zonedDateTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
325-
format = format.replace("v", isoWeek.toString());
329+
if (isoWeek >= 10) {
330+
format = format.replace("v", isoWeek.toString());
331+
} else {
332+
String isoWeekStr = "0" + isoWeek;
333+
format = format.replace("v", isoWeekStr);
334+
}
335+
}
336+
if (format.contains("V")) {
337+
Integer isoWeek = zonedDateTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
338+
if (isoWeek >= 10) {
339+
format = format.replace("V", isoWeek.toString());
340+
} else {
341+
String isoWeekStr = "0" + isoWeek;
342+
format = format.replace("V", isoWeekStr);
343+
}
326344
}
327345
if (format.contains("'y'")) {
328346
format = format.replace("'y'", "yy");
@@ -367,9 +385,27 @@ public static String xy(Date value, String format) {
367385
Integer isoYear = localDateTime.get(IsoFields.WEEK_BASED_YEAR);
368386
format = format.replace("x", isoYear.toString());
369387
}
388+
if (format.contains("X")) {
389+
Integer isoYear = localDateTime.get(IsoFields.WEEK_BASED_YEAR);
390+
format = format.replace("X", isoYear.toString());
391+
}
370392
if (format.contains("v")) {
371393
Integer isoWeek = localDateTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
372-
format = format.replace("v", isoWeek.toString());
394+
if (isoWeek >= 10) {
395+
format = format.replace("v", isoWeek.toString());
396+
} else {
397+
String isoWeekStr = "0" + isoWeek;
398+
format = format.replace("v", isoWeekStr);
399+
}
400+
}
401+
if (format.contains("V")) {
402+
Integer isoWeek = localDateTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
403+
if (isoWeek >= 10) {
404+
format = format.replace("V", isoWeek.toString());
405+
} else {
406+
String isoWeekStr = "0" + isoWeek;
407+
format = format.replace("V", isoWeekStr);
408+
}
373409
}
374410
if (format.contains("'y'")) {
375411
format = format.replace("'y'", "yy");

0 commit comments

Comments
 (0)