Search in sources :

Example 21 with ParseException

use of java.text.ParseException in project head by mifos.

the class HomePageController method loadLoanOfficerCustomersHierarchyForSelectedDay.

private void loadLoanOfficerCustomersHierarchyForSelectedDay(Short userId, ModelAndView modelAndView, CustomerSearchFormBean customerSearchFormBean) throws MifosException {
    CustomerHierarchyDto hierarchy;
    List<String> nearestDates = new ArrayList<String>();
    DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", personnelServiceFacade.getUserPreferredLocale());
    Date selectedDate = new LocalDate().toDateMidnight().toDate();
    DateTime nextDate = new DateTime();
    for (int i = 0; i < 7; i++) {
        nearestDates.add(formatter.format(nextDate.toDate()));
        nextDate = nextDate.plusDays(1);
    }
    if (customerSearchFormBean.getSelectedDateOption() != null) {
        try {
            selectedDate = formatter.parse(customerSearchFormBean.getSelectedDateOption());
        } catch (ParseException e) {
            throw new MifosException(e);
        }
    }
    hierarchy = personnelServiceFacade.getLoanOfficerCustomersHierarchyForDay(userId, new DateTime(selectedDate));
    modelAndView.addObject("nearestDates", nearestDates);
    modelAndView.addObject("hierarchy", hierarchy);
}
Also used : MifosException(org.mifos.core.MifosException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CustomerHierarchyDto(org.mifos.dto.domain.CustomerHierarchyDto) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Example 22 with ParseException

use of java.text.ParseException in project head by mifos.

the class BranchReportService method getBranchReportHeaderDTO.

@Override
public BranchReportHeaderDTO getBranchReportHeaderDTO(Integer branchId, String runDate) throws ServiceException {
    Short officeId = convertIntegerToShort(branchId);
    PersonnelBO branchManager = CollectionUtils.first(personnelBusinessService.getActiveBranchManagersUnderOffice(officeId));
    try {
        return new BranchReportHeaderDTO(officeBusinessService.getOffice(officeId), branchManager == null ? null : branchManager.getDisplayName(), ReportUtils.parseReportDate(runDate));
    } catch (ParseException e) {
        throw new ServiceException(e);
    }
}
Also used : BranchReportHeaderDTO(org.mifos.reports.business.dto.BranchReportHeaderDTO) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ParseException(java.text.ParseException) NumberUtils.convertIntegerToShort(org.mifos.framework.util.helpers.NumberUtils.convertIntegerToShort)

Example 23 with ParseException

use of java.text.ParseException in project qksms by moezbhatti.

the class DateFormatter method getSummaryTimestamp.

public static String getSummaryTimestamp(Context context, String time) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("H:mm");
    Date date;
    try {
        date = simpleDateFormat.parse(time);
        simpleDateFormat = accountFor24HourTime(context, new SimpleDateFormat("H:mm"));
        time = simpleDateFormat.format(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return time;
}
Also used : ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 24 with ParseException

use of java.text.ParseException in project mavuno by metzlerd.

the class TwitterDocument method initialize.

private void initialize() throws JSONException {
    // get json representation of the tweet
    JSONObject jobj = new JSONObject(mRawDoc.toString());
    // get tweet id 
    if (jobj.has("id")) {
        mTweetId = jobj.getLong("id");
    } else {
        mTweetId = 0;
    }
    // get tweet text
    if (jobj.has("text")) {
        mText = jobj.getString("text");
    } else {
        mText = "";
    }
    // get tweet timestamp
    if (jobj.has("created_at")) {
        try {
            mTimestamp = DATE_PARSER.parse(jobj.getString("created_at")).getTime();
        } catch (ParseException e) {
            mTimestamp = 0L;
        }
    } else {
        mTimestamp = 0L;
    }
    // is this a retweet?
    if (jobj.has("retweeted")) {
        mIsRetweet = jobj.getBoolean("retweeted") || (mText != null && mText.toLowerCase().startsWith("rt "));
    } else {
        mIsRetweet = false;
    }
    // get user information
    if (jobj.has("user")) {
        JSONObject userinfo = jobj.getJSONObject("user");
        if (userinfo.has("screen_name")) {
            mUserScreenName = userinfo.getString("screen_name");
        }
        if (userinfo.has("location")) {
            mUserLocation = userinfo.getString("location");
        } else {
            mUserLocation = "";
        }
    }
    // get geo information
    if (jobj.has("geo")) {
        try {
            JSONObject geoinfo = jobj.getJSONObject("geo");
            if (geoinfo.has("type") && geoinfo.getString("type").equals("Point") && geoinfo.has("coordinates")) {
                JSONArray coords = geoinfo.getJSONArray("coordinates");
                mUserLongitude = coords.getDouble(0);
                mUserLatitude = coords.getDouble(1);
            }
        } catch (JSONException e) {
            mUserLongitude = 0.0;
            mUserLatitude = 0.0;
        }
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ParseException(java.text.ParseException)

Example 25 with ParseException

use of java.text.ParseException in project qksms by moezbhatti.

the class NightModeAutoReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (prefs.getBoolean(SettingsFragment.NIGHT_AUTO, false)) {
        Calendar calendar = Calendar.getInstance();
        // add 5 mins in case receiver is called early
        calendar.setTimeInMillis(System.currentTimeMillis() + 300000);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("H:mm");
        Calendar day = Calendar.getInstance();
        Calendar night = Calendar.getInstance();
        try {
            day.setTime(simpleDateFormat.parse(prefs.getString(SettingsFragment.DAY_START, "6:00")));
            night.setTime(simpleDateFormat.parse(prefs.getString(SettingsFragment.NIGHT_START, "21:00")));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if ((calendar.get(Calendar.HOUR_OF_DAY) > night.get(Calendar.HOUR_OF_DAY)) || (calendar.get(Calendar.HOUR_OF_DAY) == night.get(Calendar.HOUR_OF_DAY) && calendar.get(Calendar.MINUTE) >= night.get(Calendar.MINUTE)) || (calendar.get(Calendar.HOUR_OF_DAY) < day.get(Calendar.HOUR_OF_DAY)) || (calendar.get(Calendar.HOUR_OF_DAY) == day.get(Calendar.HOUR_OF_DAY) && calendar.get(Calendar.MINUTE) <= day.get(Calendar.MINUTE))) {
            Log.i(TAG, "Switching to night mode");
            prefs.edit().putString(SettingsFragment.BACKGROUND, ThemeManager.Theme.PREF_GREY).apply();
            ThemeManager.setTheme(ThemeManager.Theme.DARK);
        } else {
            Log.i(TAG, "Switching to day mode");
            prefs.edit().putString(SettingsFragment.BACKGROUND, ThemeManager.Theme.PREF_OFFWHITE).apply();
            ThemeManager.setTheme(ThemeManager.Theme.LIGHT);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Calendar(java.util.Calendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ParseException (java.text.ParseException)3530 Date (java.util.Date)1381 SimpleDateFormat (java.text.SimpleDateFormat)1296 IOException (java.io.IOException)366 ArrayList (java.util.ArrayList)334 DateFormat (java.text.DateFormat)305 Calendar (java.util.Calendar)288 Test (org.junit.Test)274 HashMap (java.util.HashMap)139 Matcher (java.util.regex.Matcher)99 File (java.io.File)97 GregorianCalendar (java.util.GregorianCalendar)97 Map (java.util.Map)95 List (java.util.List)92 BigDecimal (java.math.BigDecimal)72 Locale (java.util.Locale)68 ParsePosition (java.text.ParsePosition)57 Timestamp (java.sql.Timestamp)55 InputStream (java.io.InputStream)53 DecimalFormat (java.text.DecimalFormat)50