-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
time zone added bug : current jalali date goes to (2 dey 2018)
- Loading branch information
Showing
14 changed files
with
333 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/DateValidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.ali.uneversaldatetools.date; | ||
|
||
/** | ||
* Created by ali on 10/2/18. | ||
*/ | ||
|
||
public class DateValidation { | ||
|
||
|
||
public static void GregorianValidate(int year, int month, int day, int hour, int min, int sec) { | ||
BaseValidate(year,month,hour, min, sec); | ||
GregorianDayValidate(year, month, day); | ||
} | ||
|
||
public static void JalaliValidate(int year, int month, int day, int hour, int min, int sec) { | ||
BaseValidate(year,month,hour, min, sec); | ||
JalaliDayValidate(year, month, day); | ||
} | ||
|
||
public static void HijriValidate(int year, int month, int day, int hour, int min, int sec) { | ||
BaseValidate(year,month,hour, min, sec); | ||
HijriDayValidate(year, month, day); | ||
} | ||
|
||
|
||
private static void GregorianDayValidate(int year, int month, int day) { | ||
|
||
//day | ||
if (DateConverter.IsGregorianLeap(year) & month == 2) { | ||
if (day < 1 | day > GregorianDateTime.DaysInMonth[month] + 1) | ||
NotValid("day",day); | ||
} else { | ||
if (day < 1 | day > GregorianDateTime.DaysInMonth[month]) | ||
NotValid("day",day); | ||
} | ||
|
||
} | ||
|
||
private static void JalaliDayValidate(int year, int month, int day) { | ||
|
||
//day | ||
if (DateConverter.IsGregorianLeap(year) & month == 12) { | ||
if (day < 1 | day > JalaliDateTime.DaysInMonth[month] + 1) | ||
NotValid("day",day); | ||
} else { | ||
if (day < 1 | day > JalaliDateTime.DaysInMonth[month]) | ||
NotValid("day",day); | ||
} | ||
|
||
} | ||
|
||
private static void HijriDayValidate(int year, int month, int day) { | ||
//day | ||
if (DateConverter.IsGregorianLeap(year) & month == 12) { | ||
if (day < 1 | day > HijriDateTime.DaysInMonth[month] + 1) | ||
NotValid("day",day); | ||
} else { | ||
if (day < 1 | day > HijriDateTime.DaysInMonth[month]) | ||
NotValid("day",day); | ||
} | ||
} | ||
|
||
|
||
private static void BaseValidate(int year, int month, int hour, int min, int sec) { | ||
|
||
//year | ||
if (year < 0) NotValid("year", year); | ||
|
||
//month | ||
if (month < 1 | month > 12) NotValid("month", month); | ||
|
||
//time | ||
if (hour > 23 | hour < 0) NotValid("hour", hour); | ||
if (min > 59 | min < 0) NotValid("minute", min); | ||
if (sec > 59 | sec < 0) NotValid("second", sec); | ||
} | ||
|
||
|
||
private static void NotValid(String what, int value) { | ||
throw new IllegalArgumentException("invalid " + what + " : " + value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.