Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arabic numbers has been replaced by Persian numbers. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
27 changes: 21 additions & 6 deletions src/test/java/com/github/eloyzone/jalalicalendar/LibTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)
Expand Down