Skip to content

Commit 7e482b1

Browse files
wt0530githubgxll
authored andcommitted
[fix][runtime] Fixed the bug of date_format
1 parent 87d7f0b commit 7e482b1

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,28 @@ 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+
344+
}
326345
}
327346
if (format.contains("'y'")) {
328347
format = format.replace("'y'", "yy");
@@ -367,9 +386,27 @@ public static String xy(Date value, String format) {
367386
Integer isoYear = localDateTime.get(IsoFields.WEEK_BASED_YEAR);
368387
format = format.replace("x", isoYear.toString());
369388
}
389+
if (format.contains("X")) {
390+
Integer isoYear = localDateTime.get(IsoFields.WEEK_BASED_YEAR);
391+
format = format.replace("X", isoYear.toString());
392+
}
370393
if (format.contains("v")) {
371394
Integer isoWeek = localDateTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
372-
format = format.replace("v", isoWeek.toString());
395+
if (isoWeek >= 10) {
396+
format = format.replace("v", isoWeek.toString());
397+
} else {
398+
String isoWeekStr = "0" + isoWeek;
399+
format = format.replace("v", isoWeekStr);
400+
}
401+
}
402+
if (format.contains("V")) {
403+
Integer isoWeek = localDateTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
404+
if (isoWeek >= 10) {
405+
format = format.replace("V", isoWeek.toString());
406+
} else {
407+
String isoWeekStr = "0" + isoWeek;
408+
format = format.replace("V", isoWeekStr);
409+
}
373410
}
374411
if (format.contains("'y'")) {
375412
format = format.replace("'y'", "yy");

0 commit comments

Comments
 (0)