Search in sources :

Example 66 with ParseException

use of java.text.ParseException in project WordPress-Android by wordpress-mobile.

the class StatsViewAllActivity method getDateForDisplayInLabels.

private String getDateForDisplayInLabels(String date, StatsTimeframe timeframe) {
    String prefix = getString(R.string.stats_for);
    switch(timeframe) {
        case DAY:
            return String.format(prefix, StatsUtils.parseDate(date, StatsConstants.STATS_INPUT_DATE_FORMAT, StatsConstants.STATS_OUTPUT_DATE_MONTH_LONG_DAY_SHORT_FORMAT));
        case WEEK:
            try {
                SimpleDateFormat sdf = new SimpleDateFormat(StatsConstants.STATS_INPUT_DATE_FORMAT);
                final Date parsedDate = sdf.parse(date);
                Calendar c = Calendar.getInstance();
                c.setTime(parsedDate);
                String endDateLabel = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_OUTPUT_DATE_MONTH_LONG_DAY_LONG_FORMAT);
                // last day of this week
                c.add(Calendar.DAY_OF_WEEK, -6);
                String startDateLabel = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_OUTPUT_DATE_MONTH_LONG_DAY_LONG_FORMAT);
                return String.format(prefix, startDateLabel + " - " + endDateLabel);
            } catch (ParseException e) {
                AppLog.e(AppLog.T.UTILS, e);
                return "";
            }
        case MONTH:
            return String.format(prefix, StatsUtils.parseDate(date, StatsConstants.STATS_INPUT_DATE_FORMAT, StatsConstants.STATS_OUTPUT_DATE_MONTH_LONG_FORMAT));
        case YEAR:
            return String.format(prefix, StatsUtils.parseDate(date, StatsConstants.STATS_INPUT_DATE_FORMAT, StatsConstants.STATS_OUTPUT_DATE_YEAR_FORMAT));
    }
    return "";
}
Also used : Calendar(java.util.Calendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 67 with ParseException

use of java.text.ParseException in project WordPress-Android by wordpress-mobile.

the class StatsVisitorsAndViewsFragment method onBarTapped.

@Override
public void onBarTapped(int tappedBar) {
    if (!isAdded()) {
        return;
    }
    //AppLog.d(AppLog.T.STATS, " Tapped bar date " + mStatsDate[tappedBar]);
    mSelectedBarGraphBarIndex = tappedBar;
    updateUIBelowTheGraph(tappedBar);
    if (!NetworkUtils.checkConnection(getActivity())) {
        return;
    }
    // Update Stats here
    String date = mStatsDate[tappedBar];
    if (date == null) {
        AppLog.w(AppLog.T.STATS, "A bar was tapped but a null date is received!!");
        return;
    }
    //Calculate the correct end date for the selected period
    String calculatedDate = null;
    try {
        SimpleDateFormat sdf;
        Calendar c = Calendar.getInstance();
        c.setFirstDayOfWeek(Calendar.MONDAY);
        final Date parsedDate;
        switch(getTimeframe()) {
            case DAY:
                calculatedDate = date;
                break;
            case WEEK:
                // first four digits are the year
                // followed by Wxx where xx is the month
                // followed by Wxx where xx is the day of the month
                // ex: 2013W07W22 = July 22, 2013
                sdf = new SimpleDateFormat("yyyy'W'MM'W'dd");
                //Calculate the end of the week
                parsedDate = sdf.parse(date);
                c.setTime(parsedDate);
                // first day of this week
                c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
                // last day of this week
                c.add(Calendar.DAY_OF_WEEK, +6);
                calculatedDate = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
                break;
            case MONTH:
                sdf = new SimpleDateFormat("yyyy-MM");
                //Calculate the end of the month
                parsedDate = sdf.parse(date);
                c.setTime(parsedDate);
                // last day of this month
                c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
                calculatedDate = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
                break;
            case YEAR:
                sdf = new SimpleDateFormat(StatsConstants.STATS_INPUT_DATE_FORMAT);
                //Calculate the end of the week
                parsedDate = sdf.parse(date);
                c.setTime(parsedDate);
                c.set(Calendar.MONTH, Calendar.DECEMBER);
                c.set(Calendar.DAY_OF_MONTH, 31);
                calculatedDate = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
                break;
        }
    } catch (ParseException e) {
        AppLog.e(AppLog.T.UTILS, e);
    }
    if (calculatedDate == null) {
        AppLog.w(AppLog.T.STATS, "A call to request new stats stats is made but date received cannot be parsed!! " + date);
        return;
    }
    // Update the data below the graph
    if (mListener != null) {
        // Should never be null
        SiteModel site = mSiteStore.getSiteByLocalId(getLocalTableBlogID());
        if (site != null && SiteUtils.isAccessibleViaWPComAPI(site)) {
            mListener.onDateChanged(site.getSiteId(), getTimeframe(), calculatedDate);
        }
    }
    AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.STATS_TAPPED_BAR_CHART, mSiteStore.getSiteByLocalId(getLocalTableBlogID()));
}
Also used : Calendar(java.util.Calendar) SiteModel(org.wordpress.android.fluxc.model.SiteModel) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 68 with ParseException

use of java.text.ParseException in project WordPress-Android by wordpress-mobile.

the class StatsUtils method getPublishedEndpointPeriodDateParameters.

//Calculate the correct start/end date for the selected period
public static String getPublishedEndpointPeriodDateParameters(StatsTimeframe timeframe, String date) {
    if (date == null) {
        AppLog.w(AppLog.T.STATS, "Can't calculate start and end period without a reference date");
        return null;
    }
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(StatsConstants.STATS_INPUT_DATE_FORMAT);
        Calendar c = Calendar.getInstance();
        c.setFirstDayOfWeek(Calendar.MONDAY);
        Date parsedDate = sdf.parse(date);
        c.setTime(parsedDate);
        final String after;
        final String before;
        switch(timeframe) {
            case DAY:
                after = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
                c.add(Calendar.DAY_OF_YEAR, +1);
                before = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
                break;
            case WEEK:
                c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
                after = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
                c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
                c.add(Calendar.DAY_OF_YEAR, +1);
                before = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
                break;
            case MONTH:
                //first day of the next month
                c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
                c.add(Calendar.DAY_OF_YEAR, +1);
                before = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
                //last day of the prev month
                c.setTime(parsedDate);
                c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
                after = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
                break;
            case YEAR:
                //first day of the next year
                c.set(Calendar.MONTH, Calendar.DECEMBER);
                c.set(Calendar.DAY_OF_MONTH, 31);
                c.add(Calendar.DAY_OF_YEAR, +1);
                before = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
                c.setTime(parsedDate);
                c.set(Calendar.MONTH, Calendar.JANUARY);
                c.set(Calendar.DAY_OF_MONTH, 1);
                after = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
                break;
            default:
                AppLog.w(AppLog.T.STATS, "Can't calculate start and end period without a reference timeframe");
                return null;
        }
        return "&after=" + after + "&before=" + before;
    } catch (ParseException e) {
        AppLog.e(AppLog.T.UTILS, e);
        return null;
    }
}
Also used : Calendar(java.util.Calendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 69 with ParseException

use of java.text.ParseException in project XobotOS by xamarin.

the class SipSessionGroup method createPeerProfile.

private static SipProfile createPeerProfile(HeaderAddress header) throws SipException {
    try {
        Address address = header.getAddress();
        SipURI uri = (SipURI) address.getURI();
        String username = uri.getUser();
        if (username == null)
            username = ANONYMOUS;
        int port = uri.getPort();
        SipProfile.Builder builder = new SipProfile.Builder(username, uri.getHost()).setDisplayName(address.getDisplayName());
        if (port > 0)
            builder.setPort(port);
        return builder.build();
    } catch (IllegalArgumentException e) {
        throw new SipException("createPeerProfile()", e);
    } catch (ParseException e) {
        throw new SipException("createPeerProfile()", e);
    }
}
Also used : HeaderAddress(javax.sip.header.HeaderAddress) Address(javax.sip.address.Address) SipProfile(android.net.sip.SipProfile) ParseException(java.text.ParseException) SipURI(javax.sip.address.SipURI) SipException(javax.sip.SipException) ListeningPoint(javax.sip.ListeningPoint)

Example 70 with ParseException

use of java.text.ParseException in project XobotOS by xamarin.

the class SipHelper method sendRinging.

/**
     * @param event the INVITE request event
     */
public ServerTransaction sendRinging(RequestEvent event, String tag) throws SipException {
    try {
        Request request = event.getRequest();
        ServerTransaction transaction = getServerTransaction(event);
        Response response = mMessageFactory.createResponse(Response.RINGING, request);
        ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
        toHeader.setTag(tag);
        response.addHeader(toHeader);
        if (DEBUG)
            Log.d(TAG, "send RINGING: " + response);
        transaction.sendResponse(response);
        return transaction;
    } catch (ParseException e) {
        throw new SipException("sendRinging()", e);
    }
}
Also used : Response(javax.sip.message.Response) Request(javax.sip.message.Request) ToHeader(javax.sip.header.ToHeader) ParseException(java.text.ParseException) ServerTransaction(javax.sip.ServerTransaction) SipException(javax.sip.SipException)

Aggregations

ParseException (java.text.ParseException)1326 Date (java.util.Date)492 SimpleDateFormat (java.text.SimpleDateFormat)465 IOException (java.io.IOException)127 DateFormat (java.text.DateFormat)123 Calendar (java.util.Calendar)115 ArrayList (java.util.ArrayList)112 Test (org.junit.Test)60 HashMap (java.util.HashMap)49 File (java.io.File)42 Matcher (java.util.regex.Matcher)41 GregorianCalendar (java.util.GregorianCalendar)35 Map (java.util.Map)29 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)27 SipException (javax.sip.SipException)26 BigDecimal (java.math.BigDecimal)25 Locale (java.util.Locale)23 Timestamp (java.sql.Timestamp)22 List (java.util.List)22 TimeZone (java.util.TimeZone)21