From 28b74005b4e29ff2784fa1000c4244dcdcba9449 Mon Sep 17 00:00:00 2001 From: Mohsen Karimi Date: Tue, 20 Jul 2021 10:49:43 +0430 Subject: [PATCH] Arabic numbers has been replaced by Persian numbers. --- .../jalalicalendar/JalaliDateFormatter.java | 20 +++++++------- .../eloyzone/jalalicalendar/LibTest.java | 27 ++++++++++++++----- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/github/eloyzone/jalalicalendar/JalaliDateFormatter.java b/src/main/java/com/github/eloyzone/jalalicalendar/JalaliDateFormatter.java index 6dc8074..ef4e9cd 100644 --- a/src/main/java/com/github/eloyzone/jalalicalendar/JalaliDateFormatter.java +++ b/src/main/java/com/github/eloyzone/jalalicalendar/JalaliDateFormatter.java @@ -195,25 +195,25 @@ private String applyFormat(int index) private char replaceWithPersian(char resultChar) { if (resultChar == '0') - return '\u0660'; + return '\u06F0'; if (resultChar == '1') - return '\u0661'; + return '\u06F1'; if (resultChar == '2') - return '\u0662'; + return '\u06F2'; if (resultChar == '3') - return '\u0663'; + return '\u06F3'; if (resultChar == '4') - return '\u0664'; + return '\u06F4'; if (resultChar == '5') - return '\u0665'; + return '\u06F5'; if (resultChar == '6') - return '\u0666'; + return '\u06F6'; if (resultChar == '7') - return '\u0667'; + return '\u06F7'; if (resultChar == '8') - return '\u0668'; + return '\u06F8'; if (resultChar == '9') - return '\u0669'; + return '\u06F9'; return resultChar; } diff --git a/src/test/java/com/github/eloyzone/jalalicalendar/LibTest.java b/src/test/java/com/github/eloyzone/jalalicalendar/LibTest.java index dc65533..7cb098b 100644 --- a/src/test/java/com/github/eloyzone/jalalicalendar/LibTest.java +++ b/src/test/java/com/github/eloyzone/jalalicalendar/LibTest.java @@ -109,12 +109,12 @@ public void jalaliFormatter() String errorMessage = "Jalali date formatter does not work properly"; String[][] persianTestCases = { - {"yyyy/mm/dd", "١٣٧٠/١١/٢٨"}, - {"yyyy/M/dd", "٢٨/بهمن/١٣٧٠"}, - {"yyyy/ M dd", "٢٨ بهمن /١٣٧٠"}, - {"yyyy- M dd", "٢٨ بهمن -١٣٧٠"}, - {"yyyy M dd", "٢٨ بهمن ١٣٧٠"}, - {"yyyyMdd", "٢٨بهمن١٣٧٠"}, + {"yyyy/mm/dd", "۱۳۷۰/۱۱/۲۸"}, + {"yyyy/M/dd", "۲۸/بهمن/۱۳۷۰"}, + {"yyyy/ M dd", "۲۸ بهمن /۱۳۷۰"}, + {"yyyy- M dd", "۲۸ بهمن -۱۳۷۰"}, + {"yyyy M dd", "۲۸ بهمن ۱۳۷۰"}, + {"yyyyMdd", "۲۸بهمن۱۳۷۰"}, }; String[][] englishTestCases = { @@ -134,6 +134,21 @@ public void jalaliFormatter() new JalaliDate(); } + @Test + public void persianNumberCheck() { + String errorMessage = "Jalali date formatter does not work properly. Make sure you enter Persian numbers not Arabic."; + + DateConverter dateConverter = new DateConverter(); + + JalaliDate jalaliDate1 = dateConverter.gregorianToJalali(1992, Month.FEBRUARY, 17); + JalaliDate jalaliDate2 = dateConverter.gregorianToJalali(2015, Month.JULY, 28); + + // We check if Persian number is entered, not Arabic. Example: ٤ => Arabic & ۴ => Persian + assertEquals(errorMessage, jalaliDate1.format(new JalaliDateFormatter("yyyy/mm/dd", JalaliDateFormatter.FORMAT_IN_PERSIAN)), "۱۳۷۰/۱۱/۲۸"); + assertEquals(errorMessage, jalaliDate2.format(new JalaliDateFormatter("yyyy/mm/dd", JalaliDateFormatter.FORMAT_IN_PERSIAN)), "۱۳۹۴/۰۵/۰۶"); + + } + // --------------------------------- Test exceptions ------------------------------------------ @Test(expected = IllegalArgumentException.class)