diff --git a/app/src/main/java/org/isoron/uhabits/helpers/DateHelper.java b/app/src/main/java/org/isoron/uhabits/helpers/DateHelper.java
index 5d6685984..4d0c02c32 100644
--- a/app/src/main/java/org/isoron/uhabits/helpers/DateHelper.java
+++ b/app/src/main/java/org/isoron/uhabits/helpers/DateHelper.java
@@ -28,9 +28,7 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
-import java.util.HashMap;
import java.util.Locale;
-import java.util.Map;
import java.util.TimeZone;
public class DateHelper
@@ -159,37 +157,13 @@ public class DateHelper
/**
- * Throughout the code, it is assumed that the weekdays are numbered
- * from 0 (Saturday) to 6 (Friday).
- *
- * see https://github.com/iSoron/uhabits/issues/74
- *
- * In the Java Calendar they are numbered from 1 (Sunday) to 7 (Saturday)
- *
- *
- *
- * day | dayNumber | wdaysIndex |
- *
- *
- * Su | 1 | 1 |
- * Mo | 2 | 2 |
- * Tu | 3 | 3 |
- * We | 4 | 4 |
- * Th | 5 | 5 |
- * Fr | 6 | 6 |
- * Sa | 7 | 0 |
- *
- *
- *
- * So we have {@code wdaysIndex = dayNumber % 7}
+ * Throughout the code, it is assumed that the weekdays are numbered from 0 (Saturday) to 6
+ * (Friday). In the Java Calendar they are numbered from 1 (Sunday) to 7 (Saturday). This
+ * function converts from Java to our internal representation.
*
* @return weekday number in the internal interpretation
- *
- * @see #getWeekday(long)
- * @see java.util.Calendar#SUNDAY
- *
*/
- public static int weekDayNumber2wdays(int number)
+ public static int javaWeekdayToLoopWeekday(int number)
{
return number % 7;
}
@@ -199,26 +173,21 @@ public class DateHelper
String[] wdays = new String[7];
Calendar day = new GregorianCalendar();
- // we start with Saturday
day.set(GregorianCalendar.DAY_OF_WEEK, Calendar.SATURDAY);
for (int i = 0; i < wdays.length; i++)
{
wdays[i] = day.getDisplayName(GregorianCalendar.DAY_OF_WEEK, format,
Locale.getDefault());
- // advance in time by one day
day.add(GregorianCalendar.DAY_OF_MONTH, 1);
}
return wdays;
}
-
/**
- *
* @return array with weekday names starting according to locale settings,
* e.g. [Mo,Di,Mi,Do,Fr,Sa,So] in Europe
- *
*/
public static String[] getLocaleDayNames(int format)
{
@@ -230,7 +199,6 @@ public class DateHelper
{
days[i] = calendar.getDisplayName(GregorianCalendar.DAY_OF_WEEK, format,
Locale.getDefault());
- // advance in time by one day
calendar.add(GregorianCalendar.DAY_OF_MONTH, 1);
}
@@ -238,42 +206,22 @@ public class DateHelper
}
/**
- *
* @return array with week days numbers starting according to locale settings,
* e.g. [2,3,4,5,6,7,1] in Europe
- *
- * @see java.util.Calendar#SUNDAY
- *
*/
public static Integer[] getLocaleWeekdayList()
{
Integer[] dayNumbers = new Integer[7];
- // a dummy calendar
Calendar calendar = new GregorianCalendar();
- // set staring day according to locale
calendar.set(GregorianCalendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
- for (int i = 0; i < dayNumbers.length; i++) {
+ for (int i = 0; i < dayNumbers.length; i++)
+ {
dayNumbers[i] = calendar.get(GregorianCalendar.DAY_OF_WEEK);
- // advance in time by one day
calendar.add(GregorianCalendar.DAY_OF_MONTH, 1);
}
return dayNumbers;
}
- /**
- * here we create the mapping of week days numbers into the "wdays"-indices
- *
- * @see DateHelper#getDayNames(int)
- */
- public static Map getWeekdayMap()
- {
- Map number2wdays = new HashMap<>();
- for (Integer number : getLocaleWeekdayList()) {
- number2wdays.put(number, number % 7);
- }
- return number2wdays;
- }
-
public static String formatWeekdayList(Context context, boolean weekday[])
{
String shortDayNames[] = getShortDayNames();
diff --git a/app/src/main/java/org/isoron/uhabits/views/HabitFrequencyView.java b/app/src/main/java/org/isoron/uhabits/views/HabitFrequencyView.java
index 2da6d6e51..86a239b36 100644
--- a/app/src/main/java/org/isoron/uhabits/views/HabitFrequencyView.java
+++ b/app/src/main/java/org/isoron/uhabits/views/HabitFrequencyView.java
@@ -35,7 +35,6 @@ import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
-import java.util.Map;
import java.util.Random;
public class HabitFrequencyView extends ScrollableDataView implements HabitDataView
@@ -234,7 +233,7 @@ public class HabitFrequencyView extends ScrollableDataView implements HabitDataV
rect.set(0, 0, baseSize, baseSize);
rect.offset(prevRect.left, prevRect.top + columnWidth * j);
- int i = DateHelper.weekDayNumber2wdays(localeWeekdayList[j]);
+ int i = DateHelper.javaWeekdayToLoopWeekday(localeWeekdayList[j]);
if(values != null)
drawMarker(canvas, rect, values[i]);
diff --git a/app/src/main/java/org/isoron/uhabits/views/HabitHistoryView.java b/app/src/main/java/org/isoron/uhabits/views/HabitHistoryView.java
index 05315ef16..95fb83a42 100644
--- a/app/src/main/java/org/isoron/uhabits/views/HabitHistoryView.java
+++ b/app/src/main/java/org/isoron/uhabits/views/HabitHistoryView.java
@@ -40,7 +40,6 @@ import org.isoron.uhabits.tasks.ToggleRepetitionTask;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
-import java.util.Map;
import java.util.Random;
public class HabitHistoryView extends ScrollableDataView implements HabitDataView,
@@ -277,7 +276,8 @@ public class HabitHistoryView extends ScrollableDataView implements HabitDataVie
{
if (!(column == nColumns - 2 && getDataOffset() == 0 && j > todayPositionInColumn))
{
- int checkmarkOffset = getDataOffset() * 7 + nDays - 7 * (column + 1) + todayPositionInColumn - j;
+ int checkmarkOffset = getDataOffset() * 7 + nDays - 7 * (column + 1) +
+ todayPositionInColumn - j;
drawSquare(canvas, location, date, checkmarkOffset);
}