Example usage for org.joda.time DateTime toString

List of usage examples for org.joda.time DateTime toString

Introduction

In this page you can find the example usage for org.joda.time DateTime toString.

Prototype

public String toString(String pattern) 

Source Link

Document

Output the instant using the specified format pattern.

Usage

From source file:com.inspireon.dragonfly.common.logging.ExtendedDailyRollingFileAppender.java

License:Apache License

int computeCheckPeriod() {
    RollingCalendar rollingCalendar = new RollingCalendar(GMT, Locale.ENGLISH);

    // set sate to 1970-01-01 00:00:00 GMT
    DateTime epoch = new DateTime(0);

    if (datePattern != null) {
        for (int i = TOP_OF_MINUTE; i <= TOP_OF_MONTH; i++) {
            //                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern);
            //                simpleDateFormat.setTimeZone(GMT); // do all date
            // formatting in GMT
            epoch = epoch.withZone(DateTimeZone.forID(Constants.TIME_ZONE_GMT));
            String r0 = epoch.toString(DateTimeFormat.forPattern(datePattern));
            //                String r0 = simpleDateFormat.format(epoch);
            rollingCalendar.setType(i);/*w  w  w.j a v a2  s .c  o m*/

            DateTime next = new DateTime(rollingCalendar.getNextCheckMillis(epoch.toDate()));
            next = next.withZone(DateTimeZone.forID(Constants.TIME_ZONE_GMT));
            String r1 = next.toString(DateTimeFormat.forPattern(datePattern));
            //                String r1 = simpleDateFormat.format(next);

            if ((r0 != null) && (r1 != null) && !r0.equals(r1)) {
                return i;
            }
        }
    }

    return TOP_OF_TROUBLE; // Deliberately head for trouble...
}

From source file:com.iukonline.amule.android.amuleremote.partfile.PartFileDetailsFragment.java

License:Open Source License

private void refreshView() {

    View v = getView();/*from   w  w w . jav  a 2s . c om*/

    if (mPartFile != null) {

        mFileNameText.setText(mPartFile.getFileName());

        String textCat = getResources().getString(R.string.partfile_details_cat_unknown);
        int backgroundColorCat = 0;
        int textColorCat = getResources().getColor(R.color.secondary_text);
        long cat = mPartFile.getCat();
        if (cat == 0) {
            textCat = getResources().getString(R.string.partfile_details_cat_nocat);

        } else {
            ECCategory[] catList = mApp.mECHelper.getCategories();
            if (catList != null) {
                for (int i = 0; i < catList.length; i++) {
                    if (catList[i].getId() == cat) {
                        textCat = catList[i].getTitle();

                        backgroundColorCat = 0xff000000 | (int) catList[i].getColor();
                        textColorCat = 0xff000000 | GUIUtils.chooseFontColor((int) catList[i].getColor());

                        break;
                    }
                }
            }
        }
        mCategoryText.setText(textCat);
        ((GradientDrawable) mCategoryText.getBackground()).setColor(backgroundColorCat);
        mCategoryText.setTextColor(textColorCat);

        mLinkText.setText(mPartFile.getEd2kLink());
        mDoneText.setText(GUIUtils.longToBytesFormatted(mPartFile.getSizeDone()));
        mSizeText.setText(GUIUtils.longToBytesFormatted(mPartFile.getSizeFull()));
        mRemainingText.setText(GUIUtils.getETA(getActivity(), mPartFile.getSizeFull() - mPartFile.getSizeDone(),
                mPartFile.getSpeed()));

        Date lastSeenComplateDate = mPartFile.getLastSeenComp();
        DateTime lastSeenComplateDateTime = new DateTime(lastSeenComplateDate);
        DateTime now = new DateTime();
        if (lastSeenComplateDate == null || lastSeenComplateDate.getTime() == 0L) {
            mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_never));
        } else {
            long lastSeenSeconds = (System.currentTimeMillis() - mPartFile.getLastSeenComp().getTime()) / 1000L;

            if (lastSeenSeconds <= 60L) {
                mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_now));
            } else if (lastSeenSeconds <= 3600L) {
                mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_mins,
                        (int) (lastSeenSeconds / 60L), lastSeenSeconds / 60L));
            } else if (lastSeenSeconds <= 86400L) {
                int lastSeenHours = (int) (lastSeenSeconds / 3600);
                if (lastSeenHours < 12 || lastSeenComplateDateTime.getDayOfMonth() == now.getDayOfMonth()) {
                    mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_hours,
                            lastSeenHours, lastSeenHours));
                } else {
                    mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_yesterday));
                }
            } else {
                int diffDays = Days.daysBetween(lastSeenComplateDateTime, now).getDays();
                if (diffDays <= 31) {
                    mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_days,
                            diffDays, diffDays));
                } else if (diffDays <= 180) {
                    int diffMonths = Months.monthsBetween(lastSeenComplateDateTime, now).getMonths();
                    mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_months,
                            diffMonths, diffMonths));
                } else {
                    mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_date,
                            lastSeenComplateDateTime.toString(DateTimeFormat.forStyle("L-")
                                    .withLocale(getResources().getConfiguration().locale))));
                }
            }
        }

        mSourcesAvailableText
                .setText(Integer.toString(mPartFile.getSourceCount() - mPartFile.getSourceNotCurrent()));
        mSourcesActiveText.setText(Integer.toString(mPartFile.getSourceXfer()));
        mSourcesA4AFText.setText(Integer.toString(mPartFile.getSourceA4AF()));
        mSourcesNotCurrentText.setText(Integer.toString(mPartFile.getSourceNotCurrent()));

        switch (mPartFile.getPrio()) {
        case ECPartFile.PR_LOW:
            mPriorityText.setText(R.string.partfile_prio_low);
            break;
        case ECPartFile.PR_NORMAL:
            mPriorityText.setText(R.string.partfile_prio_normal);
            break;
        case ECPartFile.PR_HIGH:
            mPriorityText.setText(R.string.partfile_prio_high);
            break;
        case ECPartFile.PR_AUTO_LOW:
            mPriorityText.setText(R.string.partfile_prio_auto_low);
            break;
        case ECPartFile.PR_AUTO_NORMAL:
            mPriorityText.setText(R.string.partfile_prio_auto_normal);
            break;
        case ECPartFile.PR_AUTO_HIGH:
            mPriorityText.setText(R.string.partfile_prio_auto_high);
            break;
        default:
            mPriorityText.setText(R.string.partfile_prio_unknown);
            break;
        }

        int statusColor = R.color.progressWaitingMid;

        switch (mPartFile.getStatus()) {

        case ECPartFile.PS_ALLOCATING:
            mStatusText.setText(R.string.partfile_status_allocating);
            break;
        case ECPartFile.PS_COMPLETE:
            mStatusText.setText(R.string.partfile_status_complete);
            statusColor = R.color.progressRunningMid;
            break;
        case ECPartFile.PS_COMPLETING:
            mStatusText.setText(R.string.partfile_status_completing);
            statusColor = R.color.progressRunningMid;
            break;
        case ECPartFile.PS_EMPTY:
            mStatusText.setText(R.string.partfile_status_empty);
            statusColor = R.color.progressBlockedMid;
            break;
        case ECPartFile.PS_ERROR:
            mStatusText.setText(R.string.partfile_status_error);
            statusColor = R.color.progressBlockedMid;
            break;
        case ECPartFile.PS_WAITINGFORHASH:
        case ECPartFile.PS_HASHING:
            mStatusText.setText(R.string.partfile_status_hashing);
            break;
        case ECPartFile.PS_INSUFFICIENT:
            mStatusText.setText(R.string.partfile_status_insuffcient);
            statusColor = R.color.progressBlockedMid;
            break;
        case ECPartFile.PS_PAUSED:
            mStatusText.setText(R.string.partfile_status_paused);
            break;
        case ECPartFile.PS_READY:
            if (mPartFile.getSourceXfer() > 0) {
                mStatusText.setText(R.string.partfile_status_downloading);
                mStatusText.append(" " + GUIUtils.longToBytesFormatted(mPartFile.getSpeed()) + "/s");
                statusColor = R.color.progressRunningMid;
            } else {
                mStatusText.setText(R.string.partfile_status_waiting);
                statusColor = R.color.progressWaitingMid;
            }
            break;
        case ECPartFile.PS_UNKNOWN:
            mStatusText.setText(R.string.partfile_status_unknown);
            statusColor = R.color.progressStoppedMid;
            break;
        default:
            mStatusText.setText("UNKNOWN-" + mPartFile.getStatus());
            break;
        }
        mStatusText.setTextColor(getResources().getColor(statusColor));
    }
}

From source file:com.jay.pea.mhealthapp2.presenter.AllDoseActivity.java

License:Open Source License

private void updateView() {
    listView = (ListView) findViewById(R.id.listView);
    allDoseAL = new ArrayList<>();

    dbHelper = new MedDBOpenHelper(this);
    medList = dbHelper.getAllMeds();/*from  w  w  w .j ava  2s.c  o  m*/

    HashMap<String, Integer> hashMap = new HashMap<>();

    for (Medication med : medList) {

        for (DateTime doseTime : med.getDoseMap1().keySet()) {

            DateTime takenTime = med.getDoseMap1().get(doseTime);
            String doseTimeString = doseTime.toString(dtfDate);

            if (doseTime.isBefore(new DateTime().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0))) {

                Log.d(TAG, doseTime.toString(dtfDate) + " -------- " + takenTime.toString(dtfDate));

                if (!hashMap.containsKey(doseTimeString))
                    hashMap.put(doseTimeString, 0000);

                if (takenTime.isBefore(new DateTime(0).plusYears(2))) {
                    hashMap.put(doseTimeString, hashMap.get(doseTimeString) + 1);
                } else {
                    hashMap.put(doseTimeString, hashMap.get(doseTimeString) + 100);
                }

            }
        }

    }

    Log.d("string TAG", hashMap.size() + "      ------- ");

    for (String doseDateString : hashMap.keySet()) {

        AllDoseRecord adr = new AllDoseRecord(doseDateString, hashMap.get(doseDateString) % 100,
                hashMap.get(doseDateString) / 100);
        allDoseAL.add(adr);
        Log.d("string TAG", adr.getMissedDoses() + "      " + adr.getTakenDoses() + "    " + adr.getDate());
    }

    listViewAdaptorAllDose = new CustomCardViewAdaptorAllDoseRecord(this, allDoseAL);
    if (!hashMap.isEmpty())
        listView.setAdapter(listViewAdaptorAllDose);

}

From source file:com.jay.pea.mhealthapp2.presenter.CustomCardViewMeds.java

License:Open Source License

/**
 * method to set up each card's views//  ww w. java2s .  c  om
 *
 * @param med
 */
public void setCard(Medication med) {
    //set the content for Text views of the card
    if (med.getImageRes().equals("photo")) {
        pdb = new PhotoDatabase(context);
        imageBitmap = DbBitmapUtility.getImage(pdb.getBitmapImage(med.getMedName()));
        medImage.setImageBitmap(imageBitmap);
        medImage.setBackground(null);
    } else {
        medImage.setImageResource(
                getResources().getIdentifier(med.getImageRes(), "drawable", "com.jay.pea.mhealthapp2"));
    }
    medText.setText(med.getMedString());
    if (med.getFreq() == 1) {
        doseText.setText(med.getDose() + "   Once a day");
    } else {
        doseText.setText(med.getDose() + "   " + med.getFreq() + " x a day");
    }
    DateTime start = new DateTime(med.getMedStart() * 1000l);
    DateTime end = new DateTime(med.getMedEnd() * 1000l);

    // Format for date output
    DateTimeFormatter dtf = DateTimeFormat.forPattern("dd-MMM-yy");
    String date = start.toString(dtf) + " to " + end.toString(dtf);
    dateText.setText(date);

}

From source file:com.jay.pea.mhealthapp2.presenter.CustomCardViewMissedMeds.java

License:Open Source License

/**
 * setCard method for setting up each cards views
 *
 * @param med/*from  w  w w .  j av  a 2s  .co  m*/
 */
public void setCard(Medication med) {
    //set the content for Text and Image view of each dose

    int missedDoses = 0;
    DateTime fromDate = new DateTime();
    DateTime toDate = new DateTime(0);

    for (DateTime doseDueDT : med.getDoseMap1().keySet()) {

        DateTime takenDT = med.getDoseMap1().get(doseDueDT);

        if (takenDT.equals(new DateTime(0)) && doseDueDT.isBefore(new DateTime().now())) {

            if (doseDueDT.isBefore(fromDate))
                fromDate = doseDueDT;
            if (doseDueDT.isAfter(toDate))
                toDate = doseDueDT;

            missedDoses++;
        }

    }

    if (missedDoses == 0) {
        title.setVisibility(GONE);
        textView1.setVisibility(GONE);

    }

    String missedDosesString = " missed doses";
    if (missedDoses == 1)
        missedDosesString = " missed dose";

    title.setText(med.getMedName());
    textView1.setText("You have " + missedDoses + missedDosesString + " from " + fromDate.toString(dtfDate)
            + " to " + toDate.toString(dtfDate));
    if (fromDate.toString(dtfDate).equals(toDate.toString(dtfDate)))
        textView1.setText("You have " + missedDoses + missedDosesString + " on " + fromDate.toString(dtfDate));

}

From source file:com.jay.pea.mhealthapp2.safetyMonitor.SafetyMonitor.java

License:Open Source License

/**
 * Independent Safety Monitor checks the number of doses taken per day for a medication and assures it does not exceed the required number of doses (frequency). Function must account for dismissed alarms.
 *
 * @return/* www .j ava2 s  .c o  m*/
 */
public boolean checkDoseFreq() {
    //create a dose List to match the main dose list
    ArrayList<Dose> doseList = new ArrayList<>();
    if (medList.isEmpty())
        return true;
    //get all doses and add to doseList
    for (Medication med : medList) {
        HashMap<DateTime, DateTime> doseMap1 = med.getDoseMap1();
        HashMap<DateTime, Integer> doseMap2 = med.getDoseMap2();
        for (DateTime doseDate : doseMap1.keySet()) {
            //get takenDate and alertOn
            DateTime takenDate = doseMap1.get(doseDate);
            int alertOn = doseMap2.get(doseDate);
            Dose dose = new Dose(med, doseDate, takenDate, alertOn);
            doseList.add(dose);
        }
    }
    DateTime today = new DateTime().now();
    todaysDoseList = new ArrayList<>();
    //get today's doses
    for (Dose dose : doseList) {
        DateTimeFormatter dayFormat = DateTimeFormat.forPattern("dd MMM yyyy");
        if (dose.getDoseTime().toString(dayFormat).equals(today.toString(dayFormat))) {
            todaysDoseList.add(dose);
        }
        //sort collect, add to adaptor
        Collections.sort(todaysDoseList, new DoseComparator());
    }
    for (Dose d : todaysDoseList) {
        for (Medication safeMed : safeMedList) {
            if (safeMed.getMedName().equals(d.getMedication().getMedName())
                    & safeMed.getMedStart() == (d.getMedication().getMedStart())) {
                if (d.getMedication().getFreq() == safeMed.getFreq()) {
                    return true;
                }
            }
        }
    }
    // safety fail as have not matched frequency
    return false;
}

From source file:com.jay.pea.mhealthapp2.safetyMonitor.SafetyMonitor.java

License:Open Source License

/**
 * Independent Safety Monitor checks the number of doses taken per day for a medication and assures it does not exceed the required number of doses (frequency).
 *
 * @return//from   w ww.ja  va 2s .  c o  m
 */
public boolean checkDosesTaken() {

    ArrayList<DateTime> takenAL = new ArrayList<>();
    for (Medication med : medList) {
        for (DateTime doseDateTime : med.getDoseMap1().keySet()) {
            DateTime takenDateTime = med.getDoseMap1().get(doseDateTime);
            if (takenDateTime != new DateTime(0)) {
                takenAL.add(takenDateTime);
            }
        }
    }
    int doseTakenCount = 0;
    int tempCount = 0;
    for (DateTime takenDateTime : takenAL) {
        for (DateTime innerTakenDateTime : takenAL) {
            if (innerTakenDateTime.toString(dtfDate).equals(takenDateTime.toString(dtfDate))
                    && innerTakenDateTime != takenDateTime) {
                tempCount++;
            }
        }
        if (tempCount > doseTakenCount) {
            doseTakenCount = tempCount;
        }
    }
    return true;
}

From source file:com.jay.pea.mhealthapp2.safetyMonitor.SafetyMonitor.java

License:Open Source License

/**
 * Independent Safety Monitor checks alerts are fired within one hour of dose time.
 *
 * @return/*  w  w  w.  j  av  a  2s .  com*/
 */
public boolean alertTiming() {

    if (medList.isEmpty())
        return true;

    boolean match = false;
    alertTimes = context.getSharedPreferences(PREFS_NAME_2, 0);

    for (Medication med : medList) {

        Set<String> tempS1 = alertTimes.getStringSet(med.getDose(), new HashSet<String>());

        for (String string : tempS1) {

            for (DateTime doseTime : med.getDoseMap1().keySet()) {

                if (doseTime.toString(dtfDate).equals(new DateTime().toString(dtfDate))) {

                    if (doseTime.toString(dtfTime).equals(string))
                        match = true;
                }
            }
        }
    }
    return match;
}

From source file:com.kixeye.kixmpp.date.XmppDateUtils.java

License:Apache License

/**
 * Format a DateTime to a string.//from   w w w . ja  v  a  2  s .com
 * 
 * @param dateTime
 * @return
 */
public static String format(DateTime dateTime) {
    return dateTime.toString(xmppDateTimeFormatter);
}

From source file:com.koalephant.nlp.StanfordCoreNLPHTTPServer.java

License:Open Source License

public String parse(String s, MediaType mediaType) throws IOException {
    Annotation annotation = new Annotation(s);

    DateTime now = new DateTime();

    annotation.set(DocDateAnnotation.class, now.toString(dateTimeFormatter));
    pipeline.annotate(annotation);//from  ww  w  .j a v  a  2 s .  c o m
    StringWriter sb = new StringWriter();

    switch (mediaType) {
    case TEXT_XML:
    case APPLICATION_XML:
        pipeline.xmlPrint(annotation, sb);
        break;

    case APPLICATION_JSON:
    case TEXT_JSON:
        pipeline.jsonPrint(annotation, sb);
        break;
    }

    return sb.toString();
}