use of android.text.format.Time in project Etar-Calendar by Etar-Group.
the class AllInOneActivity method onNewIntent.
@Override
protected void onNewIntent(Intent intent) {
String action = intent.getAction();
if (DEBUG)
Log.d(TAG, "New intent received " + intent.toString());
// Don't change the date if we're just returning to the app's home
if (Intent.ACTION_VIEW.equals(action) && !intent.getBooleanExtra(Utils.INTENT_KEY_HOME, false)) {
long millis = parseViewAction(intent);
if (millis == -1) {
millis = Utils.timeFromIntentInMillis(intent);
}
if (millis != -1 && mViewEventId == -1 && mController != null) {
Time time = new Time(mTimeZone);
time.set(millis);
time.normalize(true);
mController.sendEvent(this, EventType.GO_TO, time, time, -1, ViewType.CURRENT);
}
}
}
use of android.text.format.Time in project XobotOS by xamarin.
the class HttpDateTime method parse.
public static long parse(String timeString) throws IllegalArgumentException {
int date = 1;
int month = Calendar.JANUARY;
int year = 1970;
TimeOfDay timeOfDay;
Matcher rfcMatcher = HTTP_DATE_RFC_PATTERN.matcher(timeString);
if (rfcMatcher.find()) {
date = getDate(rfcMatcher.group(1));
month = getMonth(rfcMatcher.group(2));
year = getYear(rfcMatcher.group(3));
timeOfDay = getTime(rfcMatcher.group(4));
} else {
Matcher ansicMatcher = HTTP_DATE_ANSIC_PATTERN.matcher(timeString);
if (ansicMatcher.find()) {
month = getMonth(ansicMatcher.group(1));
date = getDate(ansicMatcher.group(2));
timeOfDay = getTime(ansicMatcher.group(3));
year = getYear(ansicMatcher.group(4));
} else {
throw new IllegalArgumentException();
}
}
// FIXME: Y2038 BUG!
if (year >= 2038) {
year = 2038;
month = Calendar.JANUARY;
date = 1;
}
Time time = new Time(Time.TIMEZONE_UTC);
time.set(timeOfDay.second, timeOfDay.minute, timeOfDay.hour, date, month, year);
return time.toMillis(false);
}
use of android.text.format.Time in project XobotOS by xamarin.
the class SmsCbMessage method getTimestampMillis.
/**
* Parses an ETWS primary notification timestamp and returns a currentTimeMillis()-style
* timestamp. Copied from com.android.internal.telephony.gsm.SmsMessage.
* @param pdu the ETWS primary notification PDU to decode
* @return the UTC timestamp from the Warning-Security-Information parameter
*/
private long getTimestampMillis(byte[] pdu) {
// Timestamp starts after CB header, in pdu[6]
int year = IccUtils.gsmBcdByteToInt(pdu[6]);
int month = IccUtils.gsmBcdByteToInt(pdu[7]);
int day = IccUtils.gsmBcdByteToInt(pdu[8]);
int hour = IccUtils.gsmBcdByteToInt(pdu[9]);
int minute = IccUtils.gsmBcdByteToInt(pdu[10]);
int second = IccUtils.gsmBcdByteToInt(pdu[11]);
// For the timezone, the most significant bit of the
// least significant nibble is the sign byte
// (meaning the max range of this field is 79 quarter-hours,
// which is more than enough)
byte tzByte = pdu[12];
// Mask out sign bit.
int timezoneOffset = IccUtils.gsmBcdByteToInt((byte) (tzByte & (~0x08)));
timezoneOffset = ((tzByte & 0x08) == 0) ? timezoneOffset : -timezoneOffset;
Time time = new Time(Time.TIMEZONE_UTC);
// It's 2006. Should I really support years < 2000?
time.year = year >= 90 ? year + 1900 : year + 2000;
time.month = month - 1;
time.monthDay = day;
time.hour = hour;
time.minute = minute;
time.second = second;
// Timezone offset is in quarter hours.
return time.toMillis(true) - (timezoneOffset * 15 * 60 * 1000);
}
use of android.text.format.Time in project CloudReader by youlookwhat.
the class TimeUtil method isRightTime.
/**
* 获取当前时间是否大于12:30
*/
public static boolean isRightTime() {
// or Time t=new Time("GMT+8"); 加上Time Zone资料。
Time t = new Time();
// 取得系统时间。
t.setToNow();
// 0-23
int hour = t.hour;
int minute = t.minute;
return hour > 12 || (hour == 12 && minute >= 30);
}
use of android.text.format.Time in project android_frameworks_base by ResurrectionRemix.
the class TimeTest method disableTestGetJulianDay.
@Suppress
public void disableTestGetJulianDay() throws Exception {
Time time = new Time();
// same Julian day.
for (int monthDay = 1; monthDay <= 366; monthDay++) {
for (int zoneIndex = 0; zoneIndex < mTimeZones.length; zoneIndex++) {
// We leave the "month" as zero because we are changing the
// "monthDay" from 1 to 366. The call to normalize() will
// then change the "month" (but we don't really care).
time.set(0, 0, 0, monthDay, 0, 2008);
time.timezone = mTimeZones[zoneIndex];
long millis = time.normalize(true);
if (zoneIndex == 0) {
Log.i("TimeTest", time.format("%B %d, %Y"));
}
// This is the Julian day for 12am for this day of the year
int julianDay = Time.getJulianDay(millis, time.gmtoff);
// Julian day.
for (int hour = 0; hour < 24; hour++) {
for (int minute = 0; minute < 60; minute += 15) {
time.set(0, minute, hour, monthDay, 0, 2008);
millis = time.normalize(true);
int day = Time.getJulianDay(millis, time.gmtoff);
if (day != julianDay) {
Log.e("TimeTest", "Julian day: " + day + " at time " + time.hour + ":" + time.minute + " != today's Julian day: " + julianDay + " timezone: " + time.timezone);
}
assertEquals(day, julianDay);
}
}
}
}
}
Aggregations