77import android .util .Log ;
88
99import com .blogspot .e_kanivets .moneytracker .model .Category ;
10+ import com .blogspot .e_kanivets .moneytracker .model .Period ;
1011import com .blogspot .e_kanivets .moneytracker .model .Record ;
1112import com .blogspot .e_kanivets .moneytracker .util .Constants ;
1213import com .blogspot .e_kanivets .moneytracker .util .MTApp ;
@@ -30,6 +31,8 @@ public class MTHelper extends Observable {
3031 private List <Category > categories ;
3132 private List <Record > records ;
3233
34+ private Period period ;
35+
3336 public static MTHelper getInstance () {
3437 if (mtHelper == null ) {
3538 mtHelper = new MTHelper ();
@@ -39,6 +42,8 @@ public static MTHelper getInstance() {
3942
4043 private MTHelper () {
4144 dbHelper = new DBHelper (MTApp .get ());
45+
46+ initPeriod ();
4247 }
4348
4449 public void initialize () {
@@ -204,7 +209,11 @@ public int getCategoryIdByName(String name) {
204209 return -1 ;
205210 }
206211
207- public String getFirstDayOfWeek () {
212+ public Period getPeriod () {
213+ return period ;
214+ }
215+
216+ private void initPeriod () {
208217 // get today and clear time of day
209218 Calendar cal = Calendar .getInstance ();
210219 cal .set (Calendar .HOUR_OF_DAY , 0 ); // ! clear would not reset the hour of day !
@@ -215,13 +224,8 @@ public String getFirstDayOfWeek() {
215224 // set first day of week
216225 cal .set (Calendar .DAY_OF_WEEK , cal .getFirstDayOfWeek ());
217226
218- SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm" );
219- return dateFormat .format (cal .getTime ());
220- }
227+ Date first = cal .getTime ();
221228
222- public String getLastDayOfWeek () {
223- // get today and clear time of day
224- Calendar cal = Calendar .getInstance ();
225229 cal .set (Calendar .HOUR_OF_DAY , 0 ); // ! clear would not reset the hour of day !
226230 cal .clear (Calendar .MINUTE );
227231 cal .clear (Calendar .SECOND );
@@ -233,7 +237,18 @@ public String getLastDayOfWeek() {
233237 cal .set (Calendar .MINUTE , 59 );
234238 cal .set (Calendar .SECOND , 59 );
235239
236- SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm" );
237- return dateFormat .format (cal .getTime ());
240+ Date last = cal .getTime ();
241+
242+ period = new Period (first , last );
243+ }
244+
245+ public String getFirstDayOfWeek () {
246+ SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd" );
247+ return dateFormat .format (period .getFirst ());
248+ }
249+
250+ public String getLastDayOfWeek () {
251+ SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd" );
252+ return dateFormat .format (period .getLast ());
238253 }
239254}
0 commit comments