Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit df00f65

Browse files
author
Evgeniy Kanivets
committed
Changed data concept to period
1 parent c0d8cab commit df00f65

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

app/src/main/java/com/blogspot/e_kanivets/moneytracker/helper/MTHelper.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.util.Log;
88

99
import com.blogspot.e_kanivets.moneytracker.model.Category;
10+
import com.blogspot.e_kanivets.moneytracker.model.Period;
1011
import com.blogspot.e_kanivets.moneytracker.model.Record;
1112
import com.blogspot.e_kanivets.moneytracker.util.Constants;
1213
import 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
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.blogspot.e_kanivets.moneytracker.model;
2+
3+
import java.util.Date;
4+
5+
/**
6+
* Created by eugene on 10/09/14.
7+
*/
8+
public class Period {
9+
private Date first;
10+
private Date last;
11+
12+
public Period(Date first, Date last) {
13+
this.first = first;
14+
this.last = last;
15+
}
16+
17+
public Date getFirst() {
18+
return first;
19+
}
20+
21+
public Date getLast() {
22+
return last;
23+
}
24+
}

0 commit comments

Comments
 (0)