Search in sources :

Example 56 with TimeZone

use of java.util.TimeZone in project gitblit by gitblit.

the class ReflogPanel method setup.

protected void setup(List<RefLogEntry> changes) {
    ListDataProvider<RefLogEntry> dp = new ListDataProvider<RefLogEntry>(changes);
    DataView<RefLogEntry> changeView = new DataView<RefLogEntry>("change", dp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<RefLogEntry> changeItem) {
            final RefLogEntry change = changeItem.getModelObject();
            String dateFormat = app().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy HH:mm Z");
            TimeZone timezone = getTimeZone();
            DateFormat df = new SimpleDateFormat(dateFormat);
            df.setTimeZone(timezone);
            Calendar cal = Calendar.getInstance(timezone);
            String fullRefName = change.getChangedRefs().get(0);
            String shortRefName = fullRefName;
            String ticketId = null;
            boolean isTag = false;
            boolean isTicket = false;
            if (shortRefName.startsWith(Constants.R_TICKET)) {
                ticketId = fullRefName.substring(Constants.R_TICKET.length());
                shortRefName = MessageFormat.format(getString("gb.ticketN"), ticketId);
                isTicket = true;
            } else if (shortRefName.startsWith(Constants.R_HEADS)) {
                shortRefName = shortRefName.substring(Constants.R_HEADS.length());
            } else if (shortRefName.startsWith(Constants.R_TAGS)) {
                shortRefName = shortRefName.substring(Constants.R_TAGS.length());
                isTag = true;
            }
            String fuzzydate;
            TimeUtils tu = getTimeUtils();
            Date changeDate = change.date;
            if (TimeUtils.isToday(changeDate, timezone)) {
                fuzzydate = tu.today();
            } else if (TimeUtils.isYesterday(changeDate, timezone)) {
                fuzzydate = tu.yesterday();
            } else {
                // calculate a fuzzy time ago date
                cal.setTime(changeDate);
                cal.set(Calendar.HOUR_OF_DAY, 0);
                cal.set(Calendar.MINUTE, 0);
                cal.set(Calendar.SECOND, 0);
                cal.set(Calendar.MILLISECOND, 0);
                Date date = cal.getTime();
                fuzzydate = getTimeUtils().timeAgo(date);
            }
            changeItem.add(new Label("whenChanged", fuzzydate + ", " + df.format(changeDate)));
            Label changeIcon = new Label("changeIcon");
            if (Type.DELETE.equals(change.getChangeType(fullRefName))) {
                WicketUtils.setCssClass(changeIcon, "iconic-trash-stroke");
            } else if (isTag) {
                WicketUtils.setCssClass(changeIcon, "iconic-tag");
            } else if (isTicket) {
                WicketUtils.setCssClass(changeIcon, "fa fa-ticket");
            } else {
                WicketUtils.setCssClass(changeIcon, "iconic-upload");
            }
            changeItem.add(changeIcon);
            if (change.user.username.equals(change.user.emailAddress) && change.user.emailAddress.indexOf('@') > -1) {
                // username is an email address - 1.2.1 push log bug
                changeItem.add(new Label("whoChanged", change.user.getDisplayName()));
            } else if (change.user.username.equals(UserModel.ANONYMOUS.username)) {
                // anonymous change
                changeItem.add(new Label("whoChanged", getString("gb.anonymousUser")));
            } else {
                // link to user account page
                changeItem.add(new LinkPanel("whoChanged", null, change.user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(change.user.username)));
            }
            boolean isDelete = false;
            boolean isRewind = false;
            String what;
            String by = null;
            switch(change.getChangeType(fullRefName)) {
                case CREATE:
                    if (isTag) {
                        // new tag
                        what = getString("gb.pushedNewTag");
                    } else {
                        // new branch
                        what = getString("gb.pushedNewBranch");
                    }
                    break;
                case DELETE:
                    isDelete = true;
                    if (isTag) {
                        what = getString("gb.deletedTag");
                    } else {
                        what = getString("gb.deletedBranch");
                    }
                    break;
                case UPDATE_NONFASTFORWARD:
                    isRewind = true;
                default:
                    what = MessageFormat.format(change.getCommitCount() > 1 ? getString("gb.pushedNCommitsTo") : getString("gb.pushedOneCommitTo"), change.getCommitCount());
                    if (change.getAuthorCount() == 1) {
                        by = MessageFormat.format(getString("gb.byOneAuthor"), change.getAuthorIdent().getName());
                    } else {
                        by = MessageFormat.format(getString("gb.byNAuthors"), change.getAuthorCount());
                    }
                    break;
            }
            changeItem.add(new Label("whatChanged", what));
            changeItem.add(new Label("byAuthors", by).setVisible(!StringUtils.isEmpty(by)));
            changeItem.add(new Label("refRewind", getString("gb.rewind")).setVisible(isRewind));
            if (isDelete) {
                // can't link to deleted ref
                changeItem.add(new Label("refChanged", shortRefName));
            } else if (isTag) {
                // link to tag
                changeItem.add(new LinkPanel("refChanged", null, shortRefName, TagPage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
            } else if (isTicket) {
                // link to ticket
                changeItem.add(new LinkPanel("refChanged", null, shortRefName, TicketsPage.class, WicketUtils.newObjectParameter(change.repository, ticketId)));
            } else {
                // link to tree
                changeItem.add(new LinkPanel("refChanged", null, shortRefName, TreePage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
            }
            int maxCommitCount = 5;
            List<RepositoryCommit> commits = change.getCommits();
            if (commits.size() > maxCommitCount) {
                commits = new ArrayList<RepositoryCommit>(commits.subList(0, maxCommitCount));
            }
            // compare link
            String compareLinkText = null;
            if ((change.getCommitCount() <= maxCommitCount) && (change.getCommitCount() > 1)) {
                compareLinkText = MessageFormat.format(getString("gb.viewComparison"), commits.size());
            } else if (change.getCommitCount() > maxCommitCount) {
                int diff = change.getCommitCount() - maxCommitCount;
                compareLinkText = MessageFormat.format(diff > 1 ? getString("gb.nMoreCommits") : getString("gb.oneMoreCommit"), diff);
            }
            if (StringUtils.isEmpty(compareLinkText)) {
                changeItem.add(new Label("compareLink").setVisible(false));
            } else {
                String endRangeId = change.getNewId(fullRefName);
                String startRangeId = change.getOldId(fullRefName);
                changeItem.add(new LinkPanel("compareLink", null, compareLinkText, ComparePage.class, WicketUtils.newRangeParameter(change.repository, startRangeId, endRangeId)));
            }
            ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(commits);
            DataView<RepositoryCommit> commitsView = new DataView<RepositoryCommit>("commit", cdp) {

                private static final long serialVersionUID = 1L;

                @Override
                public void populateItem(final Item<RepositoryCommit> commitItem) {
                    final RepositoryCommit commit = commitItem.getModelObject();
                    // author gravatar
                    commitItem.add(new AvatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
                    // merge icon
                    if (commit.getParentCount() > 1) {
                        commitItem.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
                    } else {
                        commitItem.add(WicketUtils.newBlankImage("commitIcon"));
                    }
                    // short message
                    String shortMessage = commit.getShortMessage();
                    String trimmedMessage = shortMessage;
                    if (commit.getRefs() != null && commit.getRefs().size() > 0) {
                        trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
                    } else {
                        trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
                    }
                    LinkPanel shortlog = new LinkPanel("commitShortMessage", "list", trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(change.repository, commit.getName()));
                    if (!shortMessage.equals(trimmedMessage)) {
                        WicketUtils.setHtmlTooltip(shortlog, shortMessage);
                    }
                    commitItem.add(shortlog);
                    // commit hash link
                    int hashLen = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
                    LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen), CommitPage.class, WicketUtils.newObjectParameter(change.repository, commit.getName()));
                    WicketUtils.setCssClass(commitHash, "shortsha1");
                    WicketUtils.setHtmlTooltip(commitHash, commit.getName());
                    commitItem.add(commitHash);
                }
            };
            changeItem.add(commitsView);
        }
    };
    add(changeView);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) Label(org.apache.wicket.markup.html.basic.Label) RefLogEntry(com.gitblit.models.RefLogEntry) TimeUtils(com.gitblit.utils.TimeUtils) Item(org.apache.wicket.markup.repeater.Item) TreePage(com.gitblit.wicket.pages.TreePage) Calendar(java.util.Calendar) ComparePage(com.gitblit.wicket.pages.ComparePage) RepositoryCommit(com.gitblit.models.RepositoryCommit) Date(java.util.Date) DataView(org.apache.wicket.markup.repeater.data.DataView) TimeZone(java.util.TimeZone) TicketsPage(com.gitblit.wicket.pages.TicketsPage) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 57 with TimeZone

use of java.util.TimeZone in project gitblit by gitblit.

the class DashboardPage method addActivity.

protected void addActivity(UserModel user, Collection<RepositoryModel> repositories, String feedTitle, int daysBack) {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, -1 * daysBack);
    Date minimumDate = c.getTime();
    TimeZone timezone = getTimeZone();
    // create daily commit digest feed
    List<DailyLogEntry> digests = new ArrayList<DailyLogEntry>();
    for (RepositoryModel model : repositories) {
        if (model.isCollectingGarbage) {
            continue;
        }
        if (model.hasCommits && model.lastChange.after(minimumDate)) {
            Repository repository = app().repositories().getRepository(model.name);
            List<DailyLogEntry> entries = RefLogUtils.getDailyLogByRef(model.name, repository, minimumDate, timezone);
            digests.addAll(entries);
            repository.close();
        }
    }
    Fragment activityFragment = new Fragment("activity", "activityFragment", this);
    add(activityFragment);
    activityFragment.add(new Label("feedTitle", feedTitle));
    if (digests.size() == 0) {
        // quiet or no starred repositories
        if (repositories.size() == 0) {
            if (UserModel.ANONYMOUS.equals(user)) {
                if (daysBack == 1) {
                    activityFragment.add(new Label("digests", getString("gb.noActivityToday")));
                } else {
                    activityFragment.add(new Label("digests", MessageFormat.format(getString("gb.noActivity"), daysBack)));
                }
            } else {
                activityFragment.add(new LinkPanel("digests", null, getString("gb.findSomeRepositories"), RepositoriesPage.class));
            }
        } else {
            if (daysBack == 1) {
                activityFragment.add(new Label("digests", getString("gb.noActivityToday")));
            } else {
                activityFragment.add(new Label("digests", MessageFormat.format(getString("gb.noActivity"), daysBack)));
            }
        }
    } else {
        // show daily commit digest feed
        Collections.sort(digests);
        DigestsPanel digestsPanel = new DigestsPanel("digests", digests);
        activityFragment.add(digestsPanel);
    }
    // add the nifty charts
    if (!ArrayUtils.isEmpty(digests)) {
        // aggregate author exclusions
        Set<String> authorExclusions = new TreeSet<String>();
        for (String author : app().settings().getStrings(Keys.web.metricAuthorExclusions)) {
            authorExclusions.add(author.toLowerCase());
        }
        for (RepositoryModel model : repositories) {
            if (!ArrayUtils.isEmpty(model.metricAuthorExclusions)) {
                for (String author : model.metricAuthorExclusions) {
                    authorExclusions.add(author.toLowerCase());
                }
            }
        }
        addCharts(activityFragment, digests, authorExclusions, daysBack);
    } else {
        activityFragment.add(new Label("charts").setVisible(false));
        activityFragment.add(new Label("feedheader").setVisible(false));
    }
}
Also used : DigestsPanel(com.gitblit.wicket.panels.DigestsPanel) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) DailyLogEntry(com.gitblit.models.DailyLogEntry) Label(org.apache.wicket.markup.html.basic.Label) RepositoryModel(com.gitblit.models.RepositoryModel) Fragment(org.apache.wicket.markup.html.panel.Fragment) Date(java.util.Date) LinkPanel(com.gitblit.wicket.panels.LinkPanel) TimeZone(java.util.TimeZone) Repository(org.eclipse.jgit.lib.Repository) TreeSet(java.util.TreeSet)

Example 58 with TimeZone

use of java.util.TimeZone in project XobotOS by xamarin.

the class CdmaServiceStateTracker method fixTimeZone.

protected void fixTimeZone(String isoCountryCode) {
    TimeZone zone = null;
    // If the offset is (0, false) and the time zone property
    // is set, use the time zone property rather than GMT.
    String zoneName = SystemProperties.get(TIMEZONE_PROPERTY);
    if ((mZoneOffset == 0) && (mZoneDst == false) && (zoneName != null) && (zoneName.length() > 0) && (Arrays.binarySearch(GMT_COUNTRY_CODES, isoCountryCode) < 0)) {
        // For NITZ string without time zone,
        // need adjust time to reflect default time zone setting
        zone = TimeZone.getDefault();
        long tzOffset;
        tzOffset = zone.getOffset(System.currentTimeMillis());
        if (getAutoTime()) {
            setAndBroadcastNetworkSetTime(System.currentTimeMillis() - tzOffset);
        } else {
            // Adjust the saved NITZ time to account for tzOffset.
            mSavedTime = mSavedTime - tzOffset;
        }
    } else if (isoCountryCode.equals("")) {
        // Country code not found. This is likely a test network.
        // Get a TimeZone based only on the NITZ parameters (best guess).
        zone = getNitzTimeZone(mZoneOffset, mZoneDst, mZoneTime);
    } else {
        zone = TimeUtils.getTimeZone(mZoneOffset, mZoneDst, mZoneTime, isoCountryCode);
    }
    mNeedFixZone = false;
    if (zone != null) {
        if (getAutoTimeZone()) {
            setAndBroadcastNetworkSetTimeZone(zone.getID());
        }
        saveNitzTimeZone(zone.getID());
    }
}
Also used : TimeZone(java.util.TimeZone)

Example 59 with TimeZone

use of java.util.TimeZone in project XobotOS by xamarin.

the class CdmaServiceStateTracker method setTimeFromNITZString.

/**
     * nitzReceiveTime is time_t that the NITZ time was posted
     */
private void setTimeFromNITZString(String nitz, long nitzReceiveTime) {
    // "yy/mm/dd,hh:mm:ss(+/-)tz"
    // tz is in number of quarter-hours
    long start = SystemClock.elapsedRealtime();
    if (DBG) {
        log("NITZ: " + nitz + "," + nitzReceiveTime + " start=" + start + " delay=" + (start - nitzReceiveTime));
    }
    try {
        /* NITZ time (hour:min:sec) will be in UTC but it supplies the timezone
             * offset as well (which we won't worry about until later) */
        Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        c.clear();
        c.set(Calendar.DST_OFFSET, 0);
        String[] nitzSubs = nitz.split("[/:,+-]");
        int year = 2000 + Integer.parseInt(nitzSubs[0]);
        c.set(Calendar.YEAR, year);
        // month is 0 based!
        int month = Integer.parseInt(nitzSubs[1]) - 1;
        c.set(Calendar.MONTH, month);
        int date = Integer.parseInt(nitzSubs[2]);
        c.set(Calendar.DATE, date);
        int hour = Integer.parseInt(nitzSubs[3]);
        c.set(Calendar.HOUR, hour);
        int minute = Integer.parseInt(nitzSubs[4]);
        c.set(Calendar.MINUTE, minute);
        int second = Integer.parseInt(nitzSubs[5]);
        c.set(Calendar.SECOND, second);
        boolean sign = (nitz.indexOf('-') == -1);
        int tzOffset = Integer.parseInt(nitzSubs[6]);
        int dst = (nitzSubs.length >= 8) ? Integer.parseInt(nitzSubs[7]) : 0;
        // The zone offset received from NITZ is for current local time,
        // so DST correction is already applied.  Don't add it again.
        //
        // tzOffset += dst * 4;
        //
        // We could unapply it if we wanted the raw offset.
        tzOffset = (sign ? 1 : -1) * tzOffset * 15 * 60 * 1000;
        TimeZone zone = null;
        // so we need to convert the ! into /
        if (nitzSubs.length >= 9) {
            String tzname = nitzSubs[8].replace('!', '/');
            zone = TimeZone.getTimeZone(tzname);
        }
        String iso = SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY);
        if (zone == null) {
            if (mGotCountryCode) {
                if (iso != null && iso.length() > 0) {
                    zone = TimeUtils.getTimeZone(tzOffset, dst != 0, c.getTimeInMillis(), iso);
                } else {
                    // We don't have a valid iso country code.  This is
                    // most likely because we're on a test network that's
                    // using a bogus MCC (eg, "001"), so get a TimeZone
                    // based only on the NITZ parameters.
                    zone = getNitzTimeZone(tzOffset, (dst != 0), c.getTimeInMillis());
                }
            }
        }
        if (zone == null) {
            // We got the time before the country, so we don't know
            // how to identify the DST rules yet.  Save the information
            // and hope to fix it up later.
            mNeedFixZone = true;
            mZoneOffset = tzOffset;
            mZoneDst = dst != 0;
            mZoneTime = c.getTimeInMillis();
        }
        if (zone != null) {
            if (getAutoTimeZone()) {
                setAndBroadcastNetworkSetTimeZone(zone.getID());
            }
            saveNitzTimeZone(zone.getID());
        }
        String ignore = SystemProperties.get("gsm.ignore-nitz");
        if (ignore != null && ignore.equals("yes")) {
            if (DBG)
                log("NITZ: Not setting clock because gsm.ignore-nitz is set");
            return;
        }
        try {
            mWakeLock.acquire();
            /**
                 * Correct the NITZ time by how long its taken to get here.
                 */
            long millisSinceNitzReceived = SystemClock.elapsedRealtime() - nitzReceiveTime;
            if (millisSinceNitzReceived < 0) {
                // Sanity check: something is wrong
                if (DBG) {
                    log("NITZ: not setting time, clock has rolled " + "backwards since NITZ time was received, " + nitz);
                }
                return;
            }
            if (millisSinceNitzReceived > Integer.MAX_VALUE) {
                // If the time is this far off, something is wrong > 24 days!
                if (DBG) {
                    log("NITZ: not setting time, processing has taken " + (millisSinceNitzReceived / (1000 * 60 * 60 * 24)) + " days");
                }
                return;
            }
            // Note: with range checks above, cast to int is safe
            c.add(Calendar.MILLISECOND, (int) millisSinceNitzReceived);
            if (getAutoTime()) {
                /**
                     * Update system time automatically
                     */
                long gained = c.getTimeInMillis() - System.currentTimeMillis();
                long timeSinceLastUpdate = SystemClock.elapsedRealtime() - mSavedAtTime;
                int nitzUpdateSpacing = Settings.Secure.getInt(cr, Settings.Secure.NITZ_UPDATE_SPACING, mNitzUpdateSpacing);
                int nitzUpdateDiff = Settings.Secure.getInt(cr, Settings.Secure.NITZ_UPDATE_DIFF, mNitzUpdateDiff);
                if ((mSavedAtTime == 0) || (timeSinceLastUpdate > nitzUpdateSpacing) || (Math.abs(gained) > nitzUpdateDiff)) {
                    if (DBG) {
                        log("NITZ: Auto updating time of day to " + c.getTime() + " NITZ receive delay=" + millisSinceNitzReceived + "ms gained=" + gained + "ms from " + nitz);
                    }
                    setAndBroadcastNetworkSetTime(c.getTimeInMillis());
                } else {
                    if (DBG) {
                        log("NITZ: ignore, a previous update was " + timeSinceLastUpdate + "ms ago and gained=" + gained + "ms");
                    }
                    return;
                }
            }
            /**
                 * Update properties and save the time we did the update
                 */
            if (DBG)
                log("NITZ: update nitz time property");
            SystemProperties.set("gsm.nitz.time", String.valueOf(c.getTimeInMillis()));
            mSavedTime = c.getTimeInMillis();
            mSavedAtTime = SystemClock.elapsedRealtime();
        } finally {
            long end = SystemClock.elapsedRealtime();
            if (DBG)
                log("NITZ: end=" + end + " dur=" + (end - start));
            mWakeLock.release();
        }
    } catch (RuntimeException ex) {
        loge("NITZ: Parsing NITZ time " + nitz + " ex=" + ex);
    }
}
Also used : TimeZone(java.util.TimeZone) Calendar(java.util.Calendar)

Example 60 with TimeZone

use of java.util.TimeZone in project XobotOS by xamarin.

the class DTTZResponseData method format.

@Override
public void format(ByteArrayOutputStream buf) {
    if (buf == null) {
        return;
    }
    // DTTZ object
    int tag = 0x80 | CommandType.PROVIDE_LOCAL_INFORMATION.value();
    // tag
    buf.write(tag);
    byte[] data = new byte[8];
    // Write length of DTTZ data
    data[0] = 0x07;
    if (calendar == null) {
        calendar = Calendar.getInstance();
    }
    // Fill year byte
    data[1] = byteToBCD(calendar.get(java.util.Calendar.YEAR) % 100);
    // Fill month byte
    data[2] = byteToBCD(calendar.get(java.util.Calendar.MONTH) + 1);
    // Fill day byte
    data[3] = byteToBCD(calendar.get(java.util.Calendar.DATE));
    // Fill hour byte
    data[4] = byteToBCD(calendar.get(java.util.Calendar.HOUR_OF_DAY));
    // Fill minute byte
    data[5] = byteToBCD(calendar.get(java.util.Calendar.MINUTE));
    // Fill second byte
    data[6] = byteToBCD(calendar.get(java.util.Calendar.SECOND));
    String tz = SystemProperties.get("persist.sys.timezone", "");
    if (TextUtils.isEmpty(tz)) {
        // set FF in terminal response
        data[7] = (byte) 0xFF;
    } else {
        TimeZone zone = TimeZone.getTimeZone(tz);
        int zoneOffset = zone.getRawOffset() + zone.getDSTSavings();
        data[7] = getTZOffSetByte(zoneOffset);
    }
    for (byte b : data) {
        buf.write(b);
    }
}
Also used : TimeZone(java.util.TimeZone)

Aggregations

TimeZone (java.util.TimeZone)577 Date (java.util.Date)140 Calendar (java.util.Calendar)137 SimpleTimeZone (java.util.SimpleTimeZone)89 Test (org.junit.Test)85 SimpleDateFormat (java.text.SimpleDateFormat)69 Locale (java.util.Locale)69 GregorianCalendar (java.util.GregorianCalendar)56 ArrayList (java.util.ArrayList)32 DateFormat (java.text.DateFormat)24 ParseException (java.text.ParseException)23 IOException (java.io.IOException)20 Map (java.util.Map)15 HashSet (java.util.HashSet)13 PreparedStatement (java.sql.PreparedStatement)11 HashMap (java.util.HashMap)11 DateTimeZone (org.joda.time.DateTimeZone)11 Support_TimeZone (tests.support.Support_TimeZone)10 Resources (android.content.res.Resources)9 SQLException (java.sql.SQLException)9