Skip to content

Commit

Permalink
fix writeDateYYYMMDD10 error, for issue #1497
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed May 19, 2023
1 parent 873450e commit 1bba7bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/com/alibaba/fastjson2/JSONWriterUTF8.java
Original file line number Diff line number Diff line change
Expand Up @@ -1990,10 +1990,10 @@ public final void writeDateYYYMMDD10(int year, int month, int dayOfMonth) {
bytes[off++] = (byte) quote;
write4(year, bytes, off);
off += 4;
bytes[off + 5] = '-';
bytes[off++] = '-';
write2(month, bytes, off);
off += 2;
bytes[off + 8] = '-';
bytes[off++] = '-';
write2(dayOfMonth, bytes, off);
off += 2;
bytes[off++] = (byte) quote;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.alibaba.fastjson2.issues_1000;

import com.alibaba.fastjson2.JSONWriter;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue1497 {
@Test
public void testUTF8() {
JSONWriter jsonWriter = JSONWriter.ofUTF8();
jsonWriter.writeDateYYYMMDD10(1921, 12, 13);
assertEquals("\"1921-12-13\"", jsonWriter.toString());
jsonWriter.close();
}

@Test
public void testUTF16() {
JSONWriter jsonWriter = JSONWriter.ofUTF16();
jsonWriter.writeDateYYYMMDD10(1921, 12, 13);
assertEquals("\"1921-12-13\"", jsonWriter.toString());
jsonWriter.close();
}
}

0 comments on commit 1bba7bf

Please sign in to comment.