Skip to content

Commit d98a7f2

Browse files
committed
1.DateModel replaced with java.Date
2.crash problem on calculating unixTime fixed bug: after year change farvardin ordibehesht swipe is bugy
1 parent a783196 commit d98a7f2

File tree

8 files changed

+205
-133
lines changed

8 files changed

+205
-133
lines changed

uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/DateSystem.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.support.annotation.Nullable;
66
import android.support.annotation.RequiresApi;
77

8+
import com.ali.uneversaldatetools.model.DateModel;
89
import com.ali.uneversaldatetools.tools.DateTools;
910

1011
import java.util.Date;
@@ -18,10 +19,10 @@
1819
public class DateSystem implements IDate, Comparable<IDate> {
1920

2021
private Calendar Calendar;
21-
private Date Date;
22+
private DateModel Date;
2223
private IDate Date_SD;
2324

24-
public DateSystem(Date date, Calendar calendar) {
25+
public DateSystem(DateModel date, Calendar calendar) {
2526
Calendar = calendar;
2627

2728
if (date.getMonth() == 0) throw new IllegalArgumentException("month cant be 0");
@@ -75,7 +76,7 @@ public Calendar getCalendar() {
7576
return Calendar;
7677
}
7778

78-
public Date getDate() {
79+
public DateModel getDate() {
7980
return Date;
8081
}
8182

@@ -111,27 +112,27 @@ public int getDays() {
111112
return Date_SD.getDays();
112113
}
113114

114-
public Date getFirstDayOfYear() {
115+
public DateModel getFirstDayOfYear() {
115116
return Date_SD.getFirstDayOfYear();
116117
}
117118

118-
public Date getLastDayOfYear() {
119+
public DateModel getLastDayOfYear() {
119120
return Date_SD.getLastDayOfYear();
120121
}
121122

122-
public Date getFirstDayOfMonth() {
123+
public DateModel getFirstDayOfMonth() {
123124
return Date_SD.getFirstDayOfMonth();
124125
}
125126

126-
public Date getLastDayOfMonth() {
127+
public DateModel getLastDayOfMonth() {
127128
return Date_SD.getLastDayOfMonth();
128129
}
129130

130-
public Date FirstDayOfSeason(Season season) {
131+
public DateModel FirstDayOfSeason(Season season) {
131132
return Date_SD.FirstDayOfSeason(season);
132133
}
133134

134-
public Date LastDayOfSeason(Season season) {
135+
public DateModel LastDayOfSeason(Season season) {
135136
return Date_SD.LastDayOfSeason(season);
136137
}
137138

@@ -159,15 +160,15 @@ public String getYearMonthLetters() {
159160
return Date_SD.getYearMonthLetters();
160161
}
161162

162-
public Date AddYears(int years) {
163+
public DateModel AddYears(int years) {
163164
return Date_SD.AddYears(years);
164165
}
165166

166-
public Date AddMonths(int months) {
167+
public DateModel AddMonths(int months) {
167168
return Date_SD.AddMonths(months);
168169
}
169170

170-
public Date AddDays(int days) {
171+
public DateModel AddDays(int days) {
171172
return Date_SD.AddDays(days);
172173
}
173174

@@ -239,7 +240,7 @@ public int compareTo(@NonNull IDate o) {
239240
}
240241

241242
public int CompareTo(IDate t2) {
242-
return Date.compareTo(t2.getDate());
243+
return Date.compareTo(t2);
243244
}
244245

245246
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@@ -256,9 +257,7 @@ public int hashCode() {
256257
return (Calendar.getValue() * 397) ^ (Date_SD.hashCode());
257258
}
258259

259-
@Override
260260
public long getUnixTime() {
261-
262261
long from = DateConverter.GregorianToDays(1970, 1, 1);
263262
return (getGregorianDateTime().getDays() - from) * 86400;
264263
}

uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/GregorianDateTime.java

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import com.ali.uneversaldatetools.model.DateModel;
66
import com.ali.uneversaldatetools.tools.DateTools;
77

8-
import java.util.Date;
9-
108
/**
119
* Created by ali on 9/5/18.
1210
*/
@@ -33,10 +31,10 @@ public class GregorianDateTime implements IDate, Comparable<GregorianDateTime> {
3331
31
3432
};
3533

36-
public GregorianDateTime(Date dateTime) {
34+
public GregorianDateTime(DateModel dateTime) {
3735
Year = dateTime.getYear();
3836
Month = dateTime.getMonth();
39-
Day = dateTime.getDate();
37+
Day = dateTime.getDay();
4038
}
4139

4240
public GregorianDateTime(int year, int month, int day) {
@@ -47,9 +45,9 @@ public GregorianDateTime(int year, int month, int day) {
4745

4846
public GregorianDateTime(int days) {
4947
DateModel sd = DateConverter.DaysToGregorian(days);
50-
Year = sd.year;
51-
Month = sd.month;
52-
Day = sd.day;
48+
Year = sd.getYear();
49+
Month = sd.getMonth();
50+
Day = sd.getDay();
5351
}
5452

5553
public static GregorianDateTime Parse(String s) {
@@ -75,37 +73,37 @@ public static GregorianDateTime Now() {
7573
return new GregorianDateTime(DateTools.getCurrentDate());
7674
}
7775

78-
public Date getDate() {
79-
return new Date(Year, Month, Day);
76+
public DateModel getDate() {
77+
return new DateModel(Year, Month, Day);
8078
}
8179

82-
public Date getFirstDayOfYear() {
83-
return new Date(Year, 1, 1);
80+
public DateModel getFirstDayOfYear() {
81+
return new DateModel(Year, 1, 1);
8482
}
8583

86-
public Date getLastDayOfYear() {
87-
return new Date(Year, 12, DaysInMonth[12], 23, 59, 59);
84+
public DateModel getLastDayOfYear() {
85+
return new DateModel(Year, 12, DaysInMonth[12], 23, 59, 59);
8886
}
8987

90-
public Date getFirstDayOfMonth() {
91-
return new Date(Year, Month, 1);
88+
public DateModel getFirstDayOfMonth() {
89+
return new DateModel(Year, Month, 1);
9290
}
9391

94-
public Date getLastDayOfMonth() {
95-
return new Date(Year, Month, DaysInMonth[Month] - (Month == 2 && !DateConverter.IsGregorianLeap(Year) ? 1 : 0), 23, 59, 59);
92+
public DateModel getLastDayOfMonth() {
93+
return new DateModel(Year, Month, DaysInMonth[Month] - (Month == 2 && !DateConverter.IsGregorianLeap(Year) ? 1 : 0), 23, 59, 59);
9694
}
9795

98-
public Date FirstDayOfSeason(Season season) {
96+
public DateModel FirstDayOfSeason(Season season) {
9997
int mSeason = season == Season.Winter ? 1 : season.getValue() + 1;
10098
int month = 1 + (mSeason - 1) * 3;
10199
return new GregorianDateTime(Year, month, 1).getDate();
102100
}
103101

104-
public Date LastDayOfSeason(Season season) {
102+
public DateModel LastDayOfSeason(Season season) {
105103
int mSeason = season == Season.Winter ? 1 : season.getValue() + 1;
106104
int month = 3 + (mSeason - 1) * 3;
107105
int day = DaysInMonth[month] - (month == 2 && !DateConverter.IsGregorianLeap(Year) ? 1 : 0);
108-
return new Date(Year, month, day, 23, 59, 59);
106+
return new DateModel(Year, month, day, 23, 59, 59);
109107
}
110108

111109
public Season getSeason() {
@@ -132,7 +130,7 @@ public Season getSeason() {
132130

133131
}
134132

135-
public Date AddYears(int years) {
133+
public DateModel AddYears(int years) {
136134
int y = Year + years;
137135
int m = Month;
138136
int maxd = DaysInMonth[m];
@@ -141,7 +139,7 @@ public Date AddYears(int years) {
141139
return new GregorianDateTime(y, m, d).getDate();
142140
}
143141

144-
public Date AddMonths(int months) {
142+
public DateModel AddMonths(int months) {
145143
int m = Month - 1 + months;
146144
int y = Year + (m / 12);
147145
m = (m % 12) + 1;
@@ -151,7 +149,7 @@ public Date AddMonths(int months) {
151149
return new GregorianDateTime(y, m, d).getDate();
152150
}
153151

154-
public Date AddDays(int days) {
152+
public DateModel AddDays(int days) {
155153
return new GregorianDateTime(getDays() + days).getDate();
156154
}
157155

@@ -243,8 +241,4 @@ public int hashCode() {
243241
hashCode = (hashCode * 397) ^ Day;
244242
return hashCode;
245243
}
246-
247-
public long getUnixTime() {
248-
return getDate().getTime() / 1000;
249-
}
250244
}

uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/HijriDateTime.java

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import com.ali.uneversaldatetools.model.DateModel;
66
import com.ali.uneversaldatetools.tools.DateTools;
77

8-
import java.util.Date;
9-
108
/**
119
* Created by ali on 9/5/18.
1210
*/
@@ -33,12 +31,12 @@ public class HijriDateTime implements IDate, Comparable<HijriDateTime> {
3331
30
3432
};
3533

36-
public HijriDateTime(Date date) {
37-
DateModel sd = DateConverter.GregorianToHijri(date.getYear(), date.getMonth(), date.getDate());
34+
public HijriDateTime(DateModel date) {
35+
DateModel sd = DateConverter.GregorianToHijri(date.getYear(), date.getMonth(), date.getDay());
3836

39-
Year = sd.year;
40-
Month = sd.month;
41-
Day = sd.day;
37+
Year = sd.getYear();
38+
Month = sd.getMonth();
39+
Day = sd.getDay();
4240
}
4341

4442
public HijriDateTime(int year, int month, int day) {
@@ -50,9 +48,9 @@ public HijriDateTime(int year, int month, int day) {
5048
public HijriDateTime(int days) {
5149
DateModel sd = DateConverter.DaysToHijri(days);
5250

53-
Year = sd.year;
54-
Month = sd.month;
55-
Day = sd.day;
51+
Year = sd.getYear();
52+
Month = sd.getMonth();
53+
Day = sd.getDay();
5654
}
5755

5856
public static HijriDateTime Parse(String date) {
@@ -78,35 +76,33 @@ public static HijriDateTime Now() {
7876
return new HijriDateTime(DateTools.getCurrentDate());
7977
}
8078

81-
82-
public Date getDate() {
79+
public DateModel getDate() {
8380
DateModel md = DateConverter.HijriToGregorian(Year, Month, Day);
84-
return new Date(md.year, md.month, md.day);
81+
return new DateModel(md.getYear(), md.getMonth(), md.getDay());
8582
}
8683

87-
88-
public Date getFirstDayOfYear() {
84+
public DateModel getFirstDayOfYear() {
8985
DateModel md = DateConverter.HijriToGregorian(Year, 1, 1);
90-
return new Date(md.year, md.month, md.day);
86+
return new DateModel(md.getYear(), md.getMonth(), md.getDay());
9187
}
9288

93-
public Date getLastDayOfYear() {
89+
public DateModel getLastDayOfYear() {
9490
DateModel md = DateConverter.HijriToGregorian(Year, 12, DaysInMonth[12] - (!DateConverter.IsHijriLeap(Year) ? 1 : 0));
95-
return new Date(md.year, md.month, md.day, 23, 59, 59);
91+
return new DateModel(md.getYear(), md.getMonth(), md.getDay(), 23, 59, 59);
9692
}
9793

98-
public Date getFirstDayOfMonth() {
94+
public DateModel getFirstDayOfMonth() {
9995
DateModel md = DateConverter.HijriToGregorian(Year, Month, 1);
100-
return new Date(md.year, md.month, md.day);
96+
return new DateModel(md.getYear(), md.getMonth(), md.getDay());
10197
}
10298

103-
public Date getLastDayOfMonth() {
99+
public DateModel getLastDayOfMonth() {
104100
DateModel md = DateConverter.HijriToGregorian(Year, Month, DaysInMonth[Month] - (Month == 12 && !DateConverter.IsHijriLeap(Year) ? 1 : 0));
105-
return new Date(md.year, md.month, md.day, 23, 59, 59);
101+
return new DateModel(md.getYear(), md.getMonth(), md.getDay(), 23, 59, 59);
106102
}
107103

108-
public Date FirstDayOfSeason(Season season) {
109-
Date mFirstDayOfSeason = new GregorianDateTime(getDate()).FirstDayOfSeason(season);
104+
public DateModel FirstDayOfSeason(Season season) {
105+
DateModel mFirstDayOfSeason = new GregorianDateTime(getDate()).FirstDayOfSeason(season);
110106
HijriDateTime firstDayOfSeason = new HijriDateTime(mFirstDayOfSeason);
111107

112108
if (firstDayOfSeason.Year == Year) {
@@ -130,7 +126,7 @@ public Date FirstDayOfSeason(Season season) {
130126
}
131127

132128

133-
public Date LastDayOfSeason(Season season) {
129+
public DateModel LastDayOfSeason(Season season) {
134130
return new GregorianDateTime(FirstDayOfSeason(season)).LastDayOfSeason(season);
135131
}
136132

@@ -158,7 +154,7 @@ public Season getSeason() {
158154
}
159155

160156

161-
public Date AddYears(int years) {
157+
public DateModel AddYears(int years) {
162158
int y = Year + years;
163159
int m = Month;
164160
int maxd = DaysInMonth[m];
@@ -168,7 +164,7 @@ public Date AddYears(int years) {
168164
}
169165

170166

171-
public Date AddMonths(int months) {
167+
public DateModel AddMonths(int months) {
172168
int m = Month - 1 + months;
173169
int y = Year + (m / 12);
174170
m = (m % 12) + 1;
@@ -179,7 +175,7 @@ public Date AddMonths(int months) {
179175
}
180176

181177

182-
public Date AddDays(int days) {
178+
public DateModel AddDays(int days) {
183179
return new HijriDateTime(getDays() + days).getDate();
184180
}
185181

@@ -285,8 +281,4 @@ public int hashCode() {
285281
hashCode = (hashCode * 397) ^ Day;
286282
return hashCode;
287283
}
288-
289-
public long getUnixTime() {
290-
return getDate().getTime() / 1000;
291-
}
292284
}
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.ali.uneversaldatetools.date;
22

3-
import java.util.Date;
3+
import com.ali.uneversaldatetools.model.DateModel;
44

55
/**
66
* Created by ali on 9/5/18.
@@ -13,24 +13,23 @@ public interface IDate {
1313
int getDay();
1414
int getDays();
1515
int getDaysOfMonth();
16-
Date getDate();
16+
DateModel getDate();
1717
JalaliDateTime getJalaliDateTime();
1818
GregorianDateTime getGregorianDateTime();
1919
HijriDateTime getHijriDateTime();
20-
Date getFirstDayOfYear();
21-
Date getLastDayOfYear ();
22-
Date getFirstDayOfMonth ();
23-
Date getLastDayOfMonth ();
24-
Date FirstDayOfSeason(Season season);
25-
Date LastDayOfSeason(Season season);
20+
DateModel getFirstDayOfYear();
21+
DateModel getLastDayOfYear ();
22+
DateModel getFirstDayOfMonth ();
23+
DateModel getLastDayOfMonth ();
24+
DateModel FirstDayOfSeason(Season season);
25+
DateModel LastDayOfSeason(Season season);
2626
Season getSeason();
2727
DayOfWeek getDayOfWeek ();
28-
Date AddYears(int years);
29-
Date AddMonths(int months);
30-
Date AddDays(int days);
28+
DateModel AddYears(int years);
29+
DateModel AddMonths(int months);
30+
DateModel AddDays(int days);
3131
String getLetters ();
3232
String getMonthLetters ();
3333
String getYearMonthLetters();
3434
String getToYearMonth();
35-
long getUnixTime();
3635
}

0 commit comments

Comments
 (0)