Example usage for org.joda.time.format DateTimeFormat forPattern

List of usage examples for org.joda.time.format DateTimeFormat forPattern

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormat forPattern.

Prototype

public static DateTimeFormatter forPattern(String pattern) 

Source Link

Document

Factory to create a formatter from a pattern string.

Usage

From source file:com.kopysoft.chronos.lib.Email.java

License:Open Source License

public String getBriefView() {
    String retString = "";
    List<DateTime> dates = punchTable.getDays();
    Chronos chron = new Chronos(gContext);
    Duration totalDuration = new Duration(0);

    for (DateTime date : dates) {
        DateTimeFormatter fmt = DateTimeFormat.forPattern("E, MMM d, yyyy");
        String time = fmt.print(date);

        Duration dur = PayPeriodAdapterList.getTime(punchTable.getPunchPair(date));
        retString += time// ww  w.  j  ava  2 s. c  o m
                + String.format(" - %02d:%02d\n", dur.toPeriod().getHours(), dur.toPeriod().getMinutes());

        totalDuration = totalDuration.plus(dur);
        Note note = chron.getNoteByDay(date);

        if (!note.getNote().equalsIgnoreCase("")) {
            retString += "\tNote: " + note.getNote() + "\n";
        }
    }

    retString += String.format("Total time - %02d:%02d\n", totalDuration.getStandardHours(),
            totalDuration.getStandardMinutes() % 60);

    chron.close();
    return retString;
}

From source file:com.kopysoft.chronos.lib.Email.java

License:Open Source License

public String getExpandedView() {
    String retString = "";
    List<DateTime> dates = punchTable.getDays();

    DateTimeFormatter dateFormat = DateTimeFormat.forPattern("E, MMM d, yyyy:\n");
    DateTimeFormatter fmt;//from  w w  w.  j a v  a2 s .  c o  m
    if (!DateFormat.is24HourFormat(gContext))
        fmt = DateTimeFormat.forPattern("h:mm a");
    else
        fmt = DateTimeFormat.forPattern("HH:mm");

    Chronos chron = new Chronos(gContext);
    Duration totalDuration = new Duration(0);

    for (DateTime date : dates) {
        if (punchTable.getPunchPair(date).size() > 0)
            retString += dateFormat.print(date);

        for (PunchPair pp : punchTable.getPunchPair(date)) {
            retString += "\t" + fmt.print(pp.getInPunch().getTime()) + " - \tIN - "
                    + pp.getInPunch().getTask().getName() + "\n";
            if (pp.getOutPunch() != null) {
                retString += "\t" + fmt.print(pp.getOutPunch().getTime()) + " - \tOUT - "
                        + pp.getOutPunch().getTask().getName() + "\n";
            }
        }

        totalDuration = totalDuration.plus(PayPeriodAdapterList.getTime(punchTable.getPunchPair(date)));

        Note note = chron.getNoteByDay(date);

        if (!note.getNote().equalsIgnoreCase("")) {
            retString += "\tNote: " + note.getNote() + "\n";
        }
    }

    retString += String.format("Total time - %02d:%02d\n", totalDuration.getStandardHours(),
            totalDuration.getStandardMinutes() % 60);

    chron.close();
    return retString;
}

From source file:com.kopysoft.chronos.views.ClockFragments.Today.DatePairView.java

License:Open Source License

private void createUI(TodayAdapterPair adpter, Job thisJob) {

    //if(enableLog) Log.d(TAG, "Position: " + position);
    setOrientation(LinearLayout.VERTICAL);

    //retView.setOnItemLongClickListener(LongClickListener);

    header = View.inflate(getContext(), R.layout.today_view, null);

    DateTimeFormatter fmt = DateTimeFormat.forPattern("E, MMM d, yyyy");
    ((TextView) header.findViewById(R.id.date)).setText(fmt.print(gDate));

    if (!showPay()) {
        header.findViewById(R.id.moneyViewText).setVisibility(View.GONE);
        header.findViewById(R.id.moneyViewTotal).setVisibility(View.GONE);
    }/*from   w  ww  .  j av a  2 s . c  o  m*/

    ListView retView = (ListView) header.findViewById(R.id.listView);
    retView.setOnItemClickListener(listener);

    TextView tx = (TextView) header.findViewById(R.id.timeViewTotal);
    Duration dur = adapter.getTime(true);

    if (dur.getMillis() < 0 && gDate.toDateMidnight().isEqual(new DateMidnight())) {
        dur = dur.plus(DateTime.now().getMillis());
    }

    int seconds = (int) dur.getStandardSeconds();
    int minutes = (seconds / 60) % 60;
    int hours = (seconds / 60 / 60);
    String output = String.format("%d:%02d:%02d", hours, minutes, seconds % 60);

    if (dur.getMillis() >= 0)
        tx.setText(output);
    else
        tx.setText("--:--:--");

    if (enableLog)
        Log.d(TAG, "job: " + thisJob);
    if (enableLog)
        Log.d(TAG, "seconds: " + seconds);
    if (enableLog)
        Log.d(TAG, "dur: " + dur.toString());
    if (enableLog)
        Log.d(TAG, "pay rate: " + thisJob.getPayRate());

    double money = adapter.getPayableTime(gDate.toDateMidnight().isEqual(new DateMidnight()));

    Currency moneyCurrency = Currency.getInstance(Locale.getDefault());
    output = String.format("%s %.2f", moneyCurrency.getSymbol(), money);
    tx = (TextView) header.findViewById(R.id.moneyViewTotal);
    tx.setText(output);
    if (enableLog)
        Log.d(TAG, "pay amount: " + output);

    //header to the row
    addView(header);

    retView.setAdapter(adpter);
    retView.setSelection(0);

    //show button
    if (!gDate.toDateMidnight().isEqual(new DateMidnight())) {
        header.findViewById(R.id.clockInAndOutButton).setVisibility(View.GONE);
    } else {
        (header.findViewById(R.id.clockInAndOutButton)).setOnClickListener(buttonListener);
        if (dur.getMillis() < 0) {
            ((Button) header.findViewById(R.id.clockInAndOutButton)).setText("Clock Out");
        } else {
            ((Button) header.findViewById(R.id.clockInAndOutButton)).setText("Clock In");
        }
    }

}

From source file:com.kubaspatny.nuntius.dto.ShortMessageDto.java

License:Apache License

public String getTimestampString() {
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    return dateTimeFormatter.print(this.mMessageTimestamp.toDateTime(DateTimeZone.forID("Europe/Prague")));
}

From source file:com.liato.bankdroid.banking.banks.americanexpress.AmericanExpress.java

License:Apache License

private Transaction asTransaction(
        com.liato.bankdroid.banking.banks.americanexpress.model.Transaction transaction) {
    return new Transaction(DateTimeFormat.forPattern("yyyyMMdd")
            .parseDateTime(Long.toString(transaction.getChargeDate().getRawValue())).toString("yyyy-MM-dd"),
            transaction.getDescription().get(0),
            new BigDecimal(transaction.getAmount().getRawValue()).negate());
}

From source file:com.ligadata.kamanja.financial.SubscriberUsageAlert.java

License:Apache License

private int getMonth(String dt) {
    DateTime jdt = DateTime.parse(dt, DateTimeFormat.forPattern("yyyyMMdd").withLocale(Locale.US));
    return jdt.monthOfYear().get();
}

From source file:com.linagora.obm.ui.scenario.event.EventStepdefs.java

License:Open Source License

@And("^event \"([^\"]*)\" is inserted in the calendar from (\\d+):(\\d+) to (\\d+):(\\d+)$")
public void eventIsInCalendar(String title, int beginHour, int beginMin, int endHour, int endMin) {
    DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm");
    String startTime = timeFormatter.print(new DateTime().withTime(beginHour, beginMin, 0, 0));
    String endTime = timeFormatter.print(new DateTime().withTime(endHour, endMin, 0, 0));

    WebElement divElement = assertEventByTitleIsInCalendar(title);

    WebElement hrefElement = divElement.findElement(new ByCssSelector("a"));
    assertThat(hrefElement.getText()).isEqualTo(startTime + " - " + endTime);
}

From source file:com.linagora.obm.ui.scenario.event.EventStepdefs.java

License:Open Source License

private String expectedEventDatesTitle(int beginHour, int beginMin, int endHour, int endMin) {
    DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm");
    return timeFormatter.print(new DateTime().withTime(beginHour, beginMin, 0, 0)) + " - "
            + timeFormatter.print(new DateTime().withTime(endHour, endMin, 0, 0));
}

From source file:com.linagora.obm.ui.scenario.event.EventStepdefs.java

License:Open Source License

@And("^event \"([^\"]*)\" appears every year at (\\d+)/(\\d+)/(\\d+) from (\\d+):(\\d+) to (\\d+):(\\d+)$")
public void eventAppearsEveryYear(String title, int day, int month, int year, int beginHour, int beginMin,
        int endHour, int endMin) {

    processedCalendarPage.calendarViewWidget().listView();
    processedCalendarPage.calendarCalRangeWidget().monthlyEvents();

    DateTime dateTime = new DateTime().withDate(year, month, day);
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
    String expectedEventDatesTitle = expectedEventDatesTitle(beginHour, beginMin, endHour, endMin);

    for (int numberOfChecks = 0; numberOfChecks < 3; numberOfChecks++) {
        boolean found = false;

        dateTime = dateTime.plusYears(1);
        for (int monthIterator = 0; monthIterator < 12; monthIterator++) {
            processedCalendarPage.calendarNavBarWidget().nextPage();
            found = isYearlyEventInPrintedMonth(title, dateTimeFormatter.print(dateTime),
                    expectedEventDatesTitle);
            if (found) {
                break;
            }//from ww w .j  a  v  a  2 s.com
        }

        assertThat(found).isTrue();
    }
}

From source file:com.linkedin.cubert.utils.DateTimeUtilities.java

License:Open Source License

public static DateTime getDateTime(String ts) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd");
    DateTime result = DateTime.parse(ts, formatter);
    return result;
}