Example usage for android.text.format Time TIMEZONE_UTC

List of usage examples for android.text.format Time TIMEZONE_UTC

Introduction

In this page you can find the example usage for android.text.format Time TIMEZONE_UTC.

Prototype

String TIMEZONE_UTC

To view the source code for android.text.format Time TIMEZONE_UTC.

Click Source Link

Usage

From source file:com.granita.icloudcalsync.DateUtils.java

public static String findAndroidTimezoneID(String tzID) {
    String localTZ = null;/*  ww  w  .ja  va 2  s . c  o m*/
    String availableTZs[] = SimpleTimeZone.getAvailableIDs();

    // first, try to find an exact match (case insensitive)
    for (String availableTZ : availableTZs)
        if (availableTZ.equalsIgnoreCase(tzID)) {
            localTZ = availableTZ;
            break;
        }

    // if that doesn't work, try to find something else that matches
    if (localTZ == null) {
        Log.w(TAG, "Coulnd't find time zone with matching identifiers, trying to guess");
        for (String availableTZ : availableTZs)
            if (StringUtils.indexOfIgnoreCase(tzID, availableTZ) != -1) {
                localTZ = availableTZ;
                break;
            }
    }

    // if that doesn't work, use UTC as fallback
    if (localTZ == null) {
        Log.e(TAG, "Couldn't identify time zone, using UTC as fallback");
        localTZ = Time.TIMEZONE_UTC;
    }

    Log.d(TAG, "Assuming time zone " + localTZ + " for " + tzID);
    return localTZ;
}

From source file:com.appsimobile.appsii.module.weather.loader.WeatherDataParser.java

public static void parseWeatherData(CircularArray<WeatherData> result, String jsonString,
        CircularArray<String> woeids) throws JSONException, ResponseParserException, ParseException {

    if (woeids.isEmpty())
        return;/*from w w  w . jav  a2  s.  co m*/

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.US);
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone(Time.TIMEZONE_UTC));

    SimpleJson json = new SimpleJson(jsonString);

    // when only a single woeid was requested, this is an object, otherwise it is an array.
    // So we need to check if we got an array; if so, handle each of the objects.
    // Otherwise get it as an object
    JSONArray resultsArray = json.getJsonArray("query.results.channel");

    if (resultsArray == null) {
        JSONObject weatherObject = json.optJsonObject("query.results.channel");
        if (weatherObject == null)
            return;

        String woeid = woeids.get(0);
        WeatherData weatherData = parseWeatherData(woeid, simpleDateFormat, weatherObject);
        if (weatherData != null) {
            result.addLast(weatherData);
        }
        return;
    }

    int length = resultsArray.length();
    for (int i = 0; i < length; i++) {
        JSONObject weatherJson = resultsArray.getJSONObject(i);
        WeatherData weatherData = parseWeatherData(woeids.get(i), simpleDateFormat, weatherJson);
        if (weatherData == null)
            continue;

        result.addLast(weatherData);

    }
}

From source file:com.metinkale.prayerapp.MainIntentService.java

private void handleCalendarIntegration() {
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
        Prefs.setCalendar("-1");
        return;/*from w  w w  . ja  v a2  s .c  om*/
    }
    Context context = App.getContext();
    try {
        ContentResolver cr = context.getContentResolver();

        cr.delete(CalendarContract.Events.CONTENT_URI,
                CalendarContract.Events.DESCRIPTION + "=\"com.metinkale.prayer\"", null);

        String id = Prefs.getCalendar();

        if ("-1".equals(id) || (Prefs.getLanguage() == null)) {
            return;
        }
        int year = LocalDate.now().getYear();
        Collection<int[]> days = new ArrayList<>();
        days.addAll(HicriDate.getHolydays(year));
        days.addAll(HicriDate.getHolydays(year + 1));

        int i = 0;
        ContentValues[] events = new ContentValues[days.size()];
        for (int[] date : days) {
            ContentValues event = new ContentValues();

            event.put(CalendarContract.Events.CALENDAR_ID, id);
            event.put(CalendarContract.Events.TITLE, Utils.getHolyday(date[HicriDate.DAY] - 1));
            event.put(CalendarContract.Events.DESCRIPTION, "com.metinkale.prayer");

            ReadableInstant cal = new DateTime(date[HicriDate.GY], date[HicriDate.GM], date[HicriDate.GD], 0, 0,
                    0);

            long dtstart = cal.getMillis();
            long dtend = dtstart + DateUtils.DAY_IN_MILLIS;

            event.put(CalendarContract.Events.DTSTART, dtstart + TimeZone.getDefault().getOffset(dtstart));
            event.put(CalendarContract.Events.DTEND, dtend + TimeZone.getDefault().getOffset(dtend));
            event.put(CalendarContract.Events.EVENT_TIMEZONE, Time.TIMEZONE_UTC);
            event.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CONFIRMED);
            event.put(CalendarContract.Events.ALL_DAY, 1);

            events[i] = event;
            i++;
        }
        cr.bulkInsert(CalendarContract.Events.CONTENT_URI, events);
    } catch (Exception e) {
        Prefs.setCalendar("-1");
        Crashlytics.logException(e);
    }
}

From source file:com.android.calendar.event.EditEventActivity.java

private EventInfo getEventInfoFromIntent(Bundle icicle) {
    EventInfo info = new EventInfo();
    long eventId = -1;
    Intent intent = getIntent();//ww  w  . j av  a 2  s.co m
    Uri data = intent.getData();
    if (data != null) {
        try {
            eventId = Long.parseLong(data.getLastPathSegment());
        } catch (NumberFormatException e) {
            if (DEBUG) {
                Log.d(TAG, "Create new event");
            }
        }
    } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
        eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
    }

    boolean allDay = intent.getBooleanExtra(EXTRA_EVENT_ALL_DAY, false);

    long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
    long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
    if (end != -1) {
        info.endTime = new Time();
        if (allDay) {
            info.endTime.timezone = Time.TIMEZONE_UTC;
        }
        info.endTime.set(end);
    }
    if (begin != -1) {
        info.startTime = new Time();
        if (allDay) {
            info.startTime.timezone = Time.TIMEZONE_UTC;
        }
        info.startTime.set(begin);
    }
    info.id = eventId;
    info.eventTitle = intent.getStringExtra(Events.TITLE);
    info.calendarId = intent.getLongExtra(Events.CALENDAR_ID, -1);

    if (allDay) {
        info.extraLong = CalendarController.EXTRA_CREATE_ALL_DAY;
    } else {
        info.extraLong = 0;
    }
    return info;
}

From source file:at.bitfire.davdroid.resource.Event.java

@Override
@SuppressWarnings("unchecked")
public void parseEntity(@NonNull InputStream entity, AssetDownloader downloader)
        throws IOException, InvalidResourceException {
    net.fortuna.ical4j.model.Calendar ical;
    try {// w w w  .  j  a va2 s  .com
        CalendarBuilder builder = new CalendarBuilder();
        ical = builder.build(entity);

        if (ical == null)
            throw new InvalidResourceException("No iCalendar found");
    } catch (ParserException e) {
        throw new InvalidResourceException(e);
    }

    // event
    ComponentList events = ical.getComponents(Component.VEVENT);
    if (events == null || events.isEmpty())
        throw new InvalidResourceException("No VEVENT found");
    VEvent event = (VEvent) events.get(0);

    if (event.getUid() != null)
        uid = event.getUid().getValue();
    else {
        Log.w(TAG, "Received VEVENT without UID, generating new one");
        generateUID();
    }

    if ((dtStart = event.getStartDate()) == null || (dtEnd = event.getEndDate()) == null)
        throw new InvalidResourceException("Invalid start time/end time/duration");

    if (hasTime(dtStart)) {
        validateTimeZone(dtStart);
        validateTimeZone(dtEnd);
    }

    // all-day events and "events on that day":
    // * related UNIX times must be in UTC
    // * must have a duration (set to one day if missing)
    if (!hasTime(dtStart) && !dtEnd.getDate().after(dtStart.getDate())) {
        Log.i(TAG, "Repairing iCal: DTEND := DTSTART+1");
        Calendar c = Calendar.getInstance(TimeZone.getTimeZone(Time.TIMEZONE_UTC));
        c.setTime(dtStart.getDate());
        c.add(Calendar.DATE, 1);
        dtEnd.setDate(new Date(c.getTimeInMillis()));
    }

    rrule = (RRule) event.getProperty(Property.RRULE);
    rdate = (RDate) event.getProperty(Property.RDATE);
    exrule = (ExRule) event.getProperty(Property.EXRULE);
    exdate = (ExDate) event.getProperty(Property.EXDATE);

    if (event.getSummary() != null)
        summary = event.getSummary().getValue();
    if (event.getLocation() != null)
        location = event.getLocation().getValue();
    if (event.getDescription() != null)
        description = event.getDescription().getValue();

    status = event.getStatus();
    opaque = event.getTransparency() != Transp.TRANSPARENT;

    organizer = event.getOrganizer();
    for (Object o : event.getProperties(Property.ATTENDEE))
        attendees.add((Attendee) o);

    Clazz classification = event.getClassification();
    if (classification != null) {
        if (classification == Clazz.PUBLIC)
            forPublic = true;
        else if (classification == Clazz.CONFIDENTIAL || classification == Clazz.PRIVATE)
            forPublic = false;
    }

    this.alarms = event.getAlarms();
}

From source file:org.privatenotes.Note.java

public void setLastChangeDate(Time lastChangeDate) {
    this.lastChangeDate = lastChangeDate;
    lastChangeDate.switchTimezone(Time.TIMEZONE_UTC);
}

From source file:Event.java

private Time getRecurrenceEnd() {
    Time until = new Time();
    //Calendar calendar = new GregorianCalendar();
    //calendar.setTime(recurrenceEnd);
    //int monthDay = calendar.get(Calendar.DAY_OF_MONTH);
    //int month = calendar.get(Calendar.MONTH);
    //int year = calendar.get(Calendar.YEAR);
    //calendar.setTime(endDate);
    //int second = calendar.get(Calendar.SECOND);
    //int minute = calendar.get(Calendar.MINUTE);
    //int hour = calendar.get(Calendar.HOUR);
    //until.set(second, minute, hour, monthDay, month, year);
    //until.second++;
    //until.normalize(false);
    until.set(recurrenceEnd.getTime());//w w  w. j av  a  2s .  c om
    until.switchTimezone(Time.TIMEZONE_UTC);
    return until;
}

From source file:org.privatenotes.Note.java

public void setLastChangeDate(String lastChangeDateStr) throws TimeFormatException {

    // regexp out the sub-milliseconds from tomboy's datetime format
    // Normal RFC 3339 format: 2008-10-13T16:00:00.000-07:00
    // Tomboy's (C# library) format: 2010-01-23T12:07:38.7743020-05:00
    Matcher m = dateCleaner.matcher(lastChangeDateStr);
    if (m.find()) {
        Log.d(TAG, "I had to clean out extra sub-milliseconds from the date");
        lastChangeDateStr = m.group(1) + m.group(2);
        Log.v(TAG, "new date: " + lastChangeDateStr);
        lastChangeDateStr = m.group(1) + m.group(2);
        Log.v(TAG, "new date: " + lastChangeDateStr);
    }//w ww  .j av  a2 s. c  o m

    lastChangeDate = new Time();
    lastChangeDate.parse3339(lastChangeDateStr);
    lastChangeDate.switchTimezone(Time.TIMEZONE_UTC);
}

From source file:org.level28.android.moca.json.ScheduleDeserializer.java

/**
 * Pure Java reimplementation of {@link Time#parse3339(String)}.
 * <p>/*  w w  w  .  j  av a 2s.c  o  m*/
 * Due to <a
 * href="http://code.google.com/p/android/issues/detail?id=16002">Issue
 * 16002</a>, {@code Time.parse3339()} leaks memory on short input. However,
 * the same leak happens <em>also</em> if the function is fed a formally
 * invalid RFC3339 timestamp.
 * <p>
 * The safest option is a full rewrite in pure Java, since JNI on Android is
 * a mess (we'd have to ship the same library for three different
 * architectures &mdash; not pretty...).
 * 
 * @param timeString
 *            a date/time specification formatted as an RFC3339 string
 * @return the same date/time specification in milliseconds since the Epoch
 * @throws ParseException
 *             if the string is formally invalid per RFC3339
 * @throws NullPointerException
 *             if the string is {@code null}
 * @throws IllegalArgumentException
 *             if the string is less than 10 characters long
 */
private static long parseTime(String timeString) throws ParseException {
    checkNotNull(timeString, "Time input should not be null");
    final int len = timeString.length();
    checkArgument(len >= 10, "Time input is too short; must be at least 10 characters");
    final char[] s = timeString.toCharArray();

    final Time t = new Time();
    int n;
    boolean inUtc = false;

    // Year
    n = getChar(s, 0, 1000);
    n += getChar(s, 1, 100);
    n += getChar(s, 2, 10);
    n += getChar(s, 3, 1);
    t.year = n;

    // '-'
    checkChar(s, 4, '-');

    // Month
    n = getChar(s, 5, 10);
    n += getChar(s, 6, 1);
    --n;
    t.month = n;

    // '-'
    checkChar(s, 7, '-');

    // Day
    n = getChar(s, 8, 10);
    n += getChar(s, 9, 1);
    t.monthDay = n;

    // Check if we have a time as well
    if (len >= 19) {
        // 'T'
        checkChar(s, 10, 'T');
        t.allDay = false;

        // Hour
        n = getChar(s, 11, 10);
        n += getChar(s, 12, 1);
        int hour = n;

        // ':'
        checkChar(s, 13, ':');

        // Minute
        n = getChar(s, 14, 10);
        n += getChar(s, 15, 1);
        int minute = n;

        // ':'
        checkChar(s, 16, ':');

        // Second
        n = getChar(s, 17, 10);
        n += getChar(s, 18, 1);
        t.second = n;

        // Skip subsecond component (if any)
        int tz_index = 19;
        if (tz_index < len && s[tz_index] == '.') {
            do {
                tz_index++;
            } while (tz_index < len && s[tz_index] >= '0' && s[tz_index] <= '9');
        }

        int offset = 0;
        if (len > tz_index) {
            final char c = s[tz_index];

            switch (c) {
            case 'Z':
                // UTC
                offset = 0;
                break;
            case '-':
                offset = 1;
                break;
            case '+':
                offset = -1;
                break;
            default:
                throw new ParseException("Unexpected character", tz_index);
            }
            inUtc = true;

            if (offset != 0) {
                // Hour
                n = getChar(s, tz_index + 1, 10);
                n += getChar(s, tz_index + 2, 1);
                n *= offset;
                hour += n;

                // ':'
                checkChar(s, tz_index + 3, ':');

                // Minute
                n = getChar(s, tz_index + 4, 10);
                n += getChar(s, tz_index + 5, 1);
                n *= offset;
                minute += n;
            }
        }
        t.hour = hour;
        t.minute = minute;

        if (offset != 0) {
            t.normalize(false);
        }
    } else {
        // We don't
        t.allDay = true;
        t.hour = 0;
        t.minute = 0;
        t.second = 0;
    }

    t.weekDay = 0;
    t.yearDay = 0;
    t.isDst = -1;
    t.gmtoff = 0;

    if (inUtc) {
        t.timezone = Time.TIMEZONE_UTC;
    }

    return t.toMillis(false);
}

From source file:at.bitfire.davdroid.resource.Event.java

protected static String getTzId(DateProperty date) {
    if (date.isUtc() || !hasTime(date))
        return Time.TIMEZONE_UTC;
    else if (date.getTimeZone() != null)
        return date.getTimeZone().getID();
    else if (date.getParameter(Value.TZID) != null)
        return date.getParameter(Value.TZID).getValue();

    // fallback//w  ww  .  j  av a  2 s.  co  m
    return Time.TIMEZONE_UTC;
}