fixed problem with incorrect string values and test
setTimeInMillis sets time in milliseconds after * January 1, 1970, 0:00:00 GMT., but our time contains timezone offsset
This commit is contained in:
parent
553fb4d0f9
commit
f901c956e5
2 changed files with 16 additions and 11 deletions
|
@ -120,7 +120,7 @@ public class TriggerTimeRange extends Trigger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String friendlyDescription() {
|
public String friendlyDescription() {
|
||||||
return MainApp.gs(R.string.timerange_value, DateUtil.timeString(toMilis(start)), DateUtil.timeString(toMilis(end)));
|
return MainApp.gs(R.string.timerange_value, DateUtil.timeString(toMilis(start) - timeZoneOffset), DateUtil.timeString(toMilis(end) - timeZoneOffset));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -150,11 +150,10 @@ public class TriggerTimeRange extends Trigger {
|
||||||
|
|
||||||
public int getMinSinceMidnight(long time) {
|
public int getMinSinceMidnight(long time) {
|
||||||
// if passed argument is smaller than 1440 ( 24 h * 60 min ) that value is already converted
|
// if passed argument is smaller than 1440 ( 24 h * 60 min ) that value is already converted
|
||||||
if (time < 1441)
|
if (0 < time && time < 1441)
|
||||||
return (int) time;
|
return (int) time;
|
||||||
Date date = new Date(time);
|
|
||||||
Calendar calendar = DateUtil.gregorianCalendar();
|
Calendar calendar = DateUtil.gregorianCalendar();
|
||||||
calendar.setTime(date);
|
calendar.setTimeInMillis(time);
|
||||||
return (calendar.get(Calendar.HOUR_OF_DAY) * 60) + calendar.get(Calendar.MINUTE);
|
return (calendar.get(Calendar.HOUR_OF_DAY) * 60) + calendar.get(Calendar.MINUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,19 +170,23 @@ public class TriggerTimeRange extends Trigger {
|
||||||
TextView label = new TextView(root.getContext());
|
TextView label = new TextView(root.getContext());
|
||||||
TextView startButton = new TextView(root.getContext());
|
TextView startButton = new TextView(root.getContext());
|
||||||
TextView endButton = new TextView(root.getContext());
|
TextView endButton = new TextView(root.getContext());
|
||||||
|
log.debug("Start is: " + start );
|
||||||
startButton.setText(DateUtil.timeString(toMilis(start)));
|
log.debug("End is: " + end );
|
||||||
endButton.setText(MainApp.gs(R.string.and) + " " + DateUtil.timeString(toMilis(end)));
|
startButton.setText(DateUtil.timeString(toMilis(start) - timeZoneOffset));
|
||||||
|
endButton.setText(MainApp.gs(R.string.and) + " " + DateUtil.timeString(toMilis(end) - timeZoneOffset));
|
||||||
|
|
||||||
startButton.setOnClickListener(view -> {
|
startButton.setOnClickListener(view -> {
|
||||||
GregorianCalendar calendar = new GregorianCalendar();
|
GregorianCalendar calendar = new GregorianCalendar();
|
||||||
calendar.setTimeInMillis(toMilis(start));
|
//setTimeInMillis sets time in milliseconds after
|
||||||
|
// * January 1, 1970, 0:00:00 GMT., but our time contains timezone offsset
|
||||||
|
calendar.setTimeInMillis(toMilis(start) - timeZoneOffset);
|
||||||
TimePickerDialog tpd = TimePickerDialog.newInstance(
|
TimePickerDialog tpd = TimePickerDialog.newInstance(
|
||||||
(view12, hourOfDay, minute, second) -> {
|
(view12, hourOfDay, minute, second) -> {
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
||||||
calendar.set(Calendar.MINUTE, minute);
|
calendar.set(Calendar.MINUTE, minute);
|
||||||
start = getMinSinceMidnight(calendar.getTimeInMillis());
|
start = getMinSinceMidnight(calendar.getTimeInMillis());
|
||||||
startButton.setText(DateUtil.timeString(toMilis(start)));
|
log.debug("Start is set to: " + start );
|
||||||
|
startButton.setText(DateUtil.timeString(toMilis(start) - timeZoneOffset));
|
||||||
},
|
},
|
||||||
calendar.get(Calendar.HOUR_OF_DAY),
|
calendar.get(Calendar.HOUR_OF_DAY),
|
||||||
calendar.get(Calendar.MINUTE),
|
calendar.get(Calendar.MINUTE),
|
||||||
|
@ -197,13 +200,14 @@ public class TriggerTimeRange extends Trigger {
|
||||||
});
|
});
|
||||||
endButton.setOnClickListener(view -> {
|
endButton.setOnClickListener(view -> {
|
||||||
GregorianCalendar calendar = new GregorianCalendar();
|
GregorianCalendar calendar = new GregorianCalendar();
|
||||||
calendar.setTimeInMillis(toMilis(end));
|
calendar.setTimeInMillis(toMilis(end) - timeZoneOffset);
|
||||||
TimePickerDialog tpd = TimePickerDialog.newInstance(
|
TimePickerDialog tpd = TimePickerDialog.newInstance(
|
||||||
(view12, hourOfDay, minute, second) -> {
|
(view12, hourOfDay, minute, second) -> {
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
||||||
calendar.set(Calendar.MINUTE, minute);
|
calendar.set(Calendar.MINUTE, minute);
|
||||||
end = getMinSinceMidnight(calendar.getTimeInMillis());
|
end = getMinSinceMidnight(calendar.getTimeInMillis());
|
||||||
endButton.setText(MainApp.gs(R.string.and) + " " + DateUtil.timeString(toMilis(end)));
|
log.debug("End is set to: " + end );
|
||||||
|
endButton.setText(MainApp.gs(R.string.and) + " " + DateUtil.timeString(toMilis(end) - timeZoneOffset));
|
||||||
},
|
},
|
||||||
calendar.get(Calendar.HOUR_OF_DAY),
|
calendar.get(Calendar.HOUR_OF_DAY),
|
||||||
calendar.get(Calendar.MINUTE),
|
calendar.get(Calendar.MINUTE),
|
||||||
|
|
|
@ -57,6 +57,7 @@ public class TriggerTimeRangeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toJSONTest() {
|
public void toJSONTest() {
|
||||||
|
now = 754;
|
||||||
TriggerTimeRange t = new TriggerTimeRange().period(now - 1, now + 30);
|
TriggerTimeRange t = new TriggerTimeRange().period(now - 1, now + 30);
|
||||||
Assert.assertEquals(timeJson, t.toJSON());
|
Assert.assertEquals(timeJson, t.toJSON());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue