List of usage examples for org.joda.time.format DateTimeFormatter print
public String print(ReadablePartial partial)
From source file:com.inbravo.scribe.rest.service.crm.zh.ZHCRMMessageFormatUtils.java
License:Open Source License
/** * // www. j a v a 2s . c o m * @param zHObjectType * @param iFieldName * @param iFieldValue * @param permittedDateFormats * @param zHInputDateFormat * @return * @throws Exception */ private static final String changeToZHDateFormat(final String iFieldValue, final String permittedDateFormats, final String zHInputDateFormat) { /* Change to ZOHO specific date format */ try { final DateTime iDT = validateInputDate(iFieldValue, permittedDateFormats); /* Create ZH specific date formatter */ final DateTimeFormatter zhDateTimeFormatter = DateTimeFormat.forPattern(zHInputDateFormat); /* Format the date to ZH specific */ return zhDateTimeFormatter.print(iDT); } catch (final Exception e) { throw new ScribeException(ScribeResponseCodes._1003 + "Following date input: " + iFieldValue + " is not acceptable at Scribe", e); } }
From source file:com.kana.connect.server.receiver.SMSKeywordDispatchReplyHandler.java
License:Apache License
/** * Helper method that transforms an SMPP Message into an XML document *///from w w w . j a va 2 s. co m public static String smppToXml(SmppReceiverMessage msg) { SMPPRequest smppReq = msg.getSmppRequest(); StringBuffer buf = new StringBuffer(); buf.append("<smpp>\n"); // smpp header // numeric values do not need to be escaped buf.append("<header>"); buf.append("<command_id>").append(smppReq.getCommandId()).append("</command_id>"); buf.append("<sequence_number>").append(smppReq.getSequenceNum()).append("</sequence_number>"); buf.append("</header>\n"); // smpp source Address smppSource = smppReq.getSource(); buf.append("<source>"); buf.append("<ton>").append(smppSource.getTON()).append("</ton>"); buf.append("<npi>").append(smppSource.getNPI()).append("</npi>"); String srcAddr = smppSource.getAddress(); srcAddr = StringEscapeUtils.escapeXml11(srcAddr); buf.append("<address>").append(srcAddr).append("</address>"); buf.append("</source>\n"); // smpp dest Address smppDest = smppReq.getDestination(); buf.append("<destination>"); buf.append("<ton>").append(smppDest.getTON()).append("</ton>"); buf.append("<npi>").append(smppDest.getNPI()).append("</npi>"); String dstAddr = smppDest.getAddress(); dstAddr = StringEscapeUtils.escapeXml11(dstAddr); buf.append("<address>").append(dstAddr).append("</address>"); buf.append("</destination>\n"); // message id String msgId = smppReq.getMessageId(); if (msgId == null) { msgId = ""; } msgId = StringEscapeUtils.escapeXml11(msgId); buf.append("<messageid>").append(msgId).append("</messageid>\n"); // smpp message String msgText = smppReq.getMessageText(); msgText = StringEscapeUtils.escapeXml11(msgText); buf.append("<message>"); buf.append(msgText); buf.append("</message>\n"); // base64 message msgText = smppReq.getMessageText(); msgText = Base64.encodeBase64String(msgText.getBytes()); buf.append("<messageBase64>"); buf.append(msgText); buf.append("</messageBase64>\n"); // // timestamps in different formats // long now = System.currentTimeMillis(); // ISO8601 http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html DateTimeFormatter isoFormat = ISODateTimeFormat.dateTime(); isoFormat.withZoneUTC(); String headerTimestamp = isoFormat.print(now); headerTimestamp = StringEscapeUtils.escapeXml11(headerTimestamp); // custom format http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html DateTimeFormatter otherFormat = DateTimeFormat.forPattern("ddMMYYYYHHmmz"); String payloadTimestamp = otherFormat.print(now); payloadTimestamp = StringEscapeUtils.escapeXml11(payloadTimestamp); buf.append("<headertimestamp>").append(headerTimestamp).append("</headertimestamp>"); buf.append("<payloadtimestamp>").append(payloadTimestamp).append("</payloadtimestamp>"); buf.append("</smpp>\n"); return buf.toString(); }
From source file:com.kopysoft.chronos.activities.Editors.NoteEditor.java
License:Open Source License
@Override public void onCreate(Bundle savedInstanceState) { if (enableLog) Log.d(TAG, "onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.note_editor); EditText editText = (EditText) findViewById(R.id.textField); TextView tv = (TextView) findViewById(R.id.date); DateTimeFormatter fmt = DateTimeFormat.forPattern("E, MMM d, yyyy"); if (savedInstanceState != null) { date = savedInstanceState.getLong("date"); Chronos chronos = new Chronos(this); gNote = chronos.getNoteByDay(new DateTime(date)); chronos.close();/*w w w.j a v a 2 s . c o m*/ editText.setText(savedInstanceState.getString("data")); } else { date = getIntent().getExtras().getLong("date"); Chronos chronos = new Chronos(this); gNote = chronos.getNoteByDay(new DateTime(date)); chronos.close(); editText.setText(gNote.getNote()); } //tv.setText(fmt.print(new DateTime(date))); tv.setText(fmt.print(gNote.getTime())); Log.d(TAG, "Note Editor with Date: " + date); getSupportActionBar().setDisplayHomeAsUpEnabled(true); //This is a workaround for http://b.android.com/15340 from http://stackoverflow.com/a/5852198/132047 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { BitmapDrawable bg = (BitmapDrawable) getResources().getDrawable(R.drawable.bg_striped); bg.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); getSupportActionBar().setBackgroundDrawable(bg); BitmapDrawable bgSplit = (BitmapDrawable) getResources().getDrawable(R.drawable.bg_striped_split_img); bgSplit.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); getSupportActionBar().setSplitBackgroundDrawable(bgSplit); } }
From source file:com.kopysoft.chronos.adapter.clock.PayPeriodAdapterList.java
License:Open Source License
@Override public View getView(int i, View view, ViewGroup viewGroup) { RowElement curr = new RowElement(gContext, 10, 15, 15, 10); TextView left = curr.left();// w w w .ja v a2 s . com TextView right = curr.right(); TextView center = curr.center(); //Reset current view center.setText(""); left.setText(""); Duration dur = getTime(getItem(i), true); if (enableLog) Log.d(TAG, "Dur Total: " + dur.getMillis()); DateTimeFormatter fmt = DateTimeFormat.forPattern("E, MMM d, yyyy"); String time = fmt.print(gPunchesByDay.getDays().get(i)); //String time = String.format("Hours %d:%02d ", dur.toPeriod().getHours(), dur.toPeriod().getMinutes()); left.setText(time); //center.setTypeface(null, Typeface.ITALIC); if (dur.getMillis() >= 0) { time = String.format("%02d:%02d ", dur.toPeriod().getHours(), dur.toPeriod().getMinutes()); right.setText(time); } else { right.setText("--:-- "); } return curr; }
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// www. j a v a 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;/*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); }//w w w. ja v a 2s .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.landenlabs.all_devtool.ClockFragment.java
License:Open Source License
/** * Update clock on screen/* w ww .j a v a2 s. c o m*/ */ private void updateClock() { m_date.setTime(System.currentTimeMillis()); m_timeZone = TimeZone.getDefault(); s_timeZoneFormat.setTimeZone(m_timeZone); String localTmStr = s_timeZoneFormat.format(m_date); m_clockLocalTv.setText(localTmStr); String gmtTmStr = s_timeGmtFormat.format(m_date); m_clockGmtTv.setText(gmtTmStr); long currDay = TimeUnit.DAYS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS); m_timePartsTv.setText(String.format("Days since Jan 1 1970: %d", currDay)); Locale ourLocale = Locale.getDefault(); StringBuilder tzStr1 = new StringBuilder(); StringBuilder tzStr2 = new StringBuilder(); tzStr1.append(String.format("Locale %s\n", ourLocale.getDisplayName())); tzStr1.append(getTzDetailStr(m_timeZone)); tzStr1.append("Daylight Savings:\n"); // tzStr.append((m_timeZone.useDaylightTime() ? "Has" : "No") + " daylight savings\n"); String ds_short = m_timeZone.getDisplayName(false, TimeZone.SHORT, ourLocale); tzStr1.append( String.format(" %s=%s\n", ds_short, m_timeZone.getDisplayName(false, TimeZone.LONG, ourLocale))); if (m_timeZone.useDaylightTime()) { String std_short = m_timeZone.getDisplayName(true, TimeZone.SHORT, ourLocale); tzStr1.append(String.format(" %s=%s\n", std_short, m_timeZone.getDisplayName(true, TimeZone.LONG, ourLocale))); // ---- // DateTimeZone zone1 = DateTimeZone.forID("Europe/London"); // DateTimeZone zone2 = DateTimeZone.forID("America/New_York"); DateTimeZone zone = DateTimeZone.forTimeZone(m_timeZone); DateTimeFormatter format = DateTimeFormat.mediumDateTime(); long current = System.currentTimeMillis(); for (int i = 0; i < 4; i++) { long next = zone.nextTransition(current); if (current == next) { break; } tzStr1.append(String.format(" %s %s\n", zone.isStandardOffset(next - 3600000) ? std_short : ds_short, format.print(next))); current = next; } m_localeTv.setText(tzStr1.toString()); String[] ids = TimeZone.getAvailableIDs(); if (ids != null && ids.length > 0) { switch (m_daylightFilter) { case NoDS: tzStr2.append("TimeZones (no Daylight savings):\n"); break; case HasDS: tzStr2.append("TimeZone (Has Daylight savings):\n"); break; case InDS: tzStr2.append("TimeZone (In Daylight savings):\n"); break; } SparseIntArray zones = new SparseIntArray(); for (int tzIdx = 0; tzIdx < ids.length; tzIdx++) { TimeZone tz = TimeZone.getTimeZone(ids[tzIdx]); boolean addTz = false; switch (m_daylightFilter) { case NoDS: addTz = !tz.useDaylightTime(); break; case HasDS: addTz = tz.useDaylightTime() && !tz.inDaylightTime(m_date); break; case InDS: addTz = tz.inDaylightTime(m_date); break; } if (addTz) { zones.put(tz.getRawOffset(), tzIdx); } } for (int idx = 0; idx != zones.size(); idx++) { TimeZone tz = TimeZone.getTimeZone(ids[zones.valueAt(idx)]); tzStr2.append(getTzOffsetStr(tz, s_timeFormat)); } } } m_dayLight.setText(tzStr2.toString()); m_clockSysClkUpTm.setText("uptimeMillis:" + formatInterval(SystemClock.uptimeMillis())); m_clockSysClkReal.setText("elapsedRealtime:" + formatInterval(SystemClock.elapsedRealtime())); }
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); }