use of android.icu.util.Calendar in project android_frameworks_base by crdroidandroid.
the class CalendarViewLegacyDelegate method setMinDate.
@Override
public void setMinDate(long minDate) {
mTempDate.setTimeInMillis(minDate);
if (isSameDate(mTempDate, mMinDate)) {
return;
}
mMinDate.setTimeInMillis(minDate);
// make sure the current date is not earlier than
// the new min date since the latter is used for
// calculating the indices in the adapter thus
// avoiding out of bounds error
Calendar date = mAdapter.mSelectedDate;
if (date.before(mMinDate)) {
mAdapter.setSelectedDay(mMinDate);
}
// reinitialize the adapter since its range depends on min date
mAdapter.init();
if (date.before(mMinDate)) {
setDate(mTempDate.getTimeInMillis());
} else {
// we go to the current date to force the ListView to query its
// adapter for the shown views since we have changed the adapter
// range and the base from which the later calculates item indices
// note that calling setDate will not work since the date is the same
goTo(date, false, true, false);
}
}
use of android.icu.util.Calendar in project android_frameworks_base by DirtyUnicorns.
the class DatePickerSpinnerDelegate method getMaxDate.
@Override
public Calendar getMaxDate() {
final Calendar maxDate = Calendar.getInstance();
maxDate.setTimeInMillis(mCalendarView.getMaxDate());
return maxDate;
}
use of android.icu.util.Calendar in project android_frameworks_base by DirtyUnicorns.
the class DateTimeView method computeNextMidnight.
/**
* @param timeZone the timezone we are in
* @return the timepoint in millis at UTC at midnight in the current timezone
*/
private long computeNextMidnight(TimeZone timeZone) {
Calendar c = Calendar.getInstance();
c.setTimeZone(libcore.icu.DateUtilsBridge.icuTimeZone(timeZone));
c.add(Calendar.DAY_OF_MONTH, 1);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTimeInMillis();
}
use of android.icu.util.Calendar in project android_frameworks_base by DirtyUnicorns.
the class TwilightService method calculateTwilightState.
/**
* Calculates the twilight state for a specific location and time.
*
* @param location the location to use
* @param timeMillis the reference time to use
* @return the calculated {@link TwilightState}, or {@code null} if location is {@code null}
*/
private static TwilightState calculateTwilightState(Location location, long timeMillis) {
if (location == null) {
return null;
}
final CalendarAstronomer ca = new CalendarAstronomer(location.getLongitude(), location.getLatitude());
final Calendar noon = Calendar.getInstance();
noon.setTimeInMillis(timeMillis);
noon.set(Calendar.HOUR_OF_DAY, 12);
noon.set(Calendar.MINUTE, 0);
noon.set(Calendar.SECOND, 0);
noon.set(Calendar.MILLISECOND, 0);
ca.setTime(noon.getTimeInMillis());
long sunriseTimeMillis = ca.getSunRiseSet(true);
long sunsetTimeMillis = ca.getSunRiseSet(false);
if (sunsetTimeMillis < timeMillis) {
noon.add(Calendar.DATE, 1);
ca.setTime(noon.getTimeInMillis());
sunriseTimeMillis = ca.getSunRiseSet(true);
} else if (sunriseTimeMillis > timeMillis) {
noon.add(Calendar.DATE, -1);
ca.setTime(noon.getTimeInMillis());
sunsetTimeMillis = ca.getSunRiseSet(false);
}
return new TwilightState(sunriseTimeMillis, sunsetTimeMillis);
}
use of android.icu.util.Calendar in project j2objc by google.
the class IBMCalendarTest method TestLeapFieldDifference.
/**
* Test behavior of fieldDifference around leap years. Also test a large
* field difference to check binary search.
*/
@Test
public void TestLeapFieldDifference() {
Calendar cal = Calendar.getInstance();
cal.set(2004, Calendar.FEBRUARY, 29);
Date date2004 = cal.getTime();
cal.set(2000, Calendar.FEBRUARY, 29);
Date date2000 = cal.getTime();
int y = cal.fieldDifference(date2004, Calendar.YEAR);
int d = cal.fieldDifference(date2004, Calendar.DAY_OF_YEAR);
if (d == 0) {
logln("Ok: 2004/Feb/29 - 2000/Feb/29 = " + y + " years, " + d + " days");
} else {
errln("FAIL: 2004/Feb/29 - 2000/Feb/29 = " + y + " years, " + d + " days");
}
cal.setTime(date2004);
y = cal.fieldDifference(date2000, Calendar.YEAR);
d = cal.fieldDifference(date2000, Calendar.DAY_OF_YEAR);
if (d == 0) {
logln("Ok: 2000/Feb/29 - 2004/Feb/29 = " + y + " years, " + d + " days");
} else {
errln("FAIL: 2000/Feb/29 - 2004/Feb/29 = " + y + " years, " + d + " days");
}
// Test large difference
// 2452005
cal.set(2001, Calendar.APRIL, 5);
Date ayl = cal.getTime();
// 2438646
cal.set(1964, Calendar.SEPTEMBER, 7);
Date asl = cal.getTime();
d = cal.fieldDifference(ayl, Calendar.DAY_OF_MONTH);
cal.setTime(ayl);
int d2 = cal.fieldDifference(asl, Calendar.DAY_OF_MONTH);
if (d == -d2 && d == 13359) {
logln("Ok: large field difference symmetrical " + d);
} else {
logln("FAIL: large field difference incorrect " + d + ", " + d2 + ", expect +/- 13359");
}
}
Aggregations