List of usage examples for org.joda.time DateTime getYearOfCentury
public int getYearOfCentury()
From source file:com.addthis.hydra.job.backup.WeeklyBackup.java
License:Apache License
@Override public String getFormattedDateString(long timeMillis) { // For better handling of days at the end of the year. DateTime dt = new DateTime(timeMillis); if (dt.monthOfYear().get() == 12 && dt.weekOfWeekyear().get() < 3) { return dt.getYearOfCentury() + "53"; }//from w w w . ja v a 2s . c o m return Integer.toString(dt.getYearOfCentury()) + String.format("%02d", dt.weekOfWeekyear().get()); }
From source file:com.barchart.feed.test.replay.DDFLogDeframer.java
License:BSD License
static final void encodeTimeStamp(final String timestamp, final ByteBuffer buffer) { DateTime dateTime = timeParser.parseDateTime(timestamp); // base fields buffer.put(DDF_CENTURY); // century buffer.put(encodeTimeStampByte(dateTime.getYearOfCentury())); // year buffer.put(encodeTimeStampByte(dateTime.getMonthOfYear())); // month buffer.put(encodeTimeStampByte(dateTime.getDayOfMonth())); // day buffer.put(encodeTimeStampByte(dateTime.getHourOfDay())); // hours buffer.put(encodeTimeStampByte(dateTime.getMinuteOfHour())); // minutes buffer.put(encodeTimeStampByte(dateTime.getSecondOfMinute())); // seconds // milliseconds final int millisOfSecond = dateTime.getMillisOfSecond(); buffer.put((byte) (millisOfSecond & 0xFF)); // low byte buffer.put((byte) ((millisOfSecond >>> 8) & 0xFF)); // high byte }
From source file:com.clevercloud.bianca.lib.date.DateModule.java
License:Open Source License
/** * Returns the parsed date./* w w w . j a v a 2 s . c o m*/ */ public Value strptime(Env env, String date, String format) { ArrayValueImpl array = new ArrayValueImpl(); DateTimeFormatterBuilder fb = new DateTimeFormatterBuilder(); int length = format.length(); for (int i = 0; i < length; i++) { char ch = format.charAt(i); if (ch != '%') { fb.appendLiteral(ch); continue; } switch (format.charAt(++i)) { case 'a': fb.appendDayOfWeekShortText(); break; case 'A': fb.appendDayOfWeekText(); break; case 'h': case 'b': fb.appendMonthOfYearShortText(); ; break; case 'B': fb.appendMonthOfYearText(); break; // TODO: case 'c' case 'C': fb.appendCenturyOfEra(2, 2); break; case 'd': fb.appendDayOfMonth(2); break; case 'D': fb.appendMonthOfYear(2); fb.appendLiteral('/'); fb.appendDayOfMonth(2); fb.appendLiteral('/'); fb.appendYear(2, 2); break; // TODO: case 'e' case 'F': fb.appendYear(4, 4); fb.appendLiteral('-'); fb.appendMonthOfYear(2); fb.appendLiteral('-'); fb.appendDayOfMonth(2); break; // TODO: case 'g' // TODO: case 'G' case 'H': fb.appendHourOfDay(2); break; case 'I': fb.appendHourOfHalfday(2); break; case 'j': fb.appendDayOfYear(3); break; // TODO: case 'l' case 'm': fb.appendMonthOfYear(2); break; case 'M': fb.appendMinuteOfHour(2); break; case 'n': fb.appendLiteral("\n"); break; case 'p': case 'P': fb.appendHalfdayOfDayText(); break; case 'r': fb.appendHourOfHalfday(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); fb.appendLiteral(':'); fb.appendSecondOfMinute(2); fb.appendLiteral(' '); fb.appendHalfdayOfDayText(); break; case 'R': fb.appendHourOfDay(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); break; // TODO: case 's' case 'S': fb.appendSecondOfMinute(2); break; case 't': fb.appendLiteral("\t"); break; case 'T': fb.appendHourOfDay(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); fb.appendLiteral(':'); fb.appendSecondOfMinute(2); break; // TODO: case 'u' // TODO: case 'U' // TODO: case 'V' // TODO: case 'w' // TODO: case 'W' // TODO: case 'x' // TODO: case 'X' case 'y': fb.appendYear(2, 2); break; case 'Y': fb.appendYear(4, 4); break; case 'z': fb.appendTimeZoneOffset(null, true, 2, 2); break; case 'Z': fb.appendTimeZoneName(); break; case '%': fb.appendLiteral('%'); break; default: fb.appendLiteral(ch); } } DateTimeFormatter dtf = fb.toFormatter().withLocale(Locale.getDefault()).withOffsetParsed(); org.joda.time.DateTime dt = new org.joda.time.DateTime(); String unparsed = ""; try { dt = dtf.parseDateTime(date); } catch (IllegalArgumentException e) { String delims = "[\"]+"; String[] splits = e.getMessage().split(delims); unparsed = unparsed.concat(splits[3]); } // According to manual strptime(3) if (dt.getCenturyOfEra() == 0) { if (dt.getYear() > 68) { dt = dt.withCenturyOfEra(19); } else { dt = dt.withCenturyOfEra(20); } } array.put("tm_sec", dt.getSecondOfMinute()); array.put("tm_min", dt.getMinuteOfHour()); array.put("tm_hour", dt.getHourOfDay()); array.put("tm_mday", dt.getDayOfMonth()); array.put("tm_mon", dt.getMonthOfYear() - 1); array.put("tm_year", dt.getYearOfCentury() + ((dt.getCenturyOfEra() - 19) * 100)); // Years since 1900 array.put("tm_wday", dt.getDayOfWeek() % 7); array.put("tm_yday", dt.getDayOfYear() - 1); array.put("unparsed", unparsed); return array; }
From source file:com.squarespace.template.plugins.PluginDateUtils.java
License:Apache License
/** * Takes a strftime()-compatible format string and outputs the properly formatted date. *///from w w w . j a v a 2s. co m public static void formatDate(Locale locale, String fmt, long instant, String tzName, StringBuilder buf) { DateTimeZone zone = null; try { zone = DateTimeZone.forID(tzName); } catch (IllegalArgumentException e) { zone = DateTimeZone.getDefault(); } DateTime date = new DateTime(instant, zone); int index = 0; int len = fmt.length(); while (index < len) { char c1 = fmt.charAt(index); index++; if (c1 != '%' || index == len) { buf.append(c1); continue; } char c2 = fmt.charAt(index); switch (c2) { case 'A': buf.append(date.dayOfWeek().getAsText(locale)); break; case 'a': buf.append(date.dayOfWeek().getAsShortText(locale)); break; case 'B': buf.append(date.monthOfYear().getAsText(locale)); break; case 'b': buf.append(date.monthOfYear().getAsShortText(locale)); break; case 'C': leftPad(date.centuryOfEra().get(), '0', 2, buf); break; case 'c': formatAggregate(DateTimeAggregate.FULL, locale, date, buf); break; case 'D': formatAggregate(DateTimeAggregate.MMDDYY, locale, date, buf); break; case 'd': leftPad(date.dayOfMonth().get(), '0', 2, buf); break; case 'e': leftPad(date.dayOfMonth().get(), ' ', 2, buf); break; case 'F': formatAggregate(DateTimeAggregate.YYYYMMDD, locale, date, buf); break; case 'G': buf.append(date.year().get()); break; case 'g': leftPad(date.yearOfCentury().get(), '0', 2, buf); break; case 'H': leftPad(date.hourOfDay().get(), '0', 2, buf); break; case 'h': buf.append(date.monthOfYear().getAsShortText(locale)); break; case 'I': leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), '0', 2, buf); break; case 'j': leftPad(date.dayOfYear().get(), '0', 3, buf); break; case 'k': leftPad(date.get(DateTimeFieldType.clockhourOfDay()), ' ', 2, buf); break; case 'l': leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), ' ', 2, buf); break; case 'M': leftPad(date.minuteOfHour().get(), '0', 2, buf); break; case 'm': leftPad(date.monthOfYear().get(), '0', 2, buf); break; case 'n': buf.append('\n'); break; case 'P': buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "am" : "pm"); break; case 'p': buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "AM" : "PM"); break; case 'R': formatAggregate(DateTimeAggregate.H240_M0, locale, date, buf); break; case 'S': leftPad(date.secondOfMinute().get(), '0', 2, buf); break; case 's': buf.append(instant / 1000); break; case 't': buf.append('\t'); break; case 'T': // Equivalent of %H:%M:%S formatAggregate(DateTimeAggregate.H240_M0, locale, date, buf); buf.append(':'); leftPad(date.secondOfMinute().get(), '0', 2, buf); break; case 'U': // TODO: fix week-of-year number leftPad(date.weekOfWeekyear().get(), '0', 2, buf); break; case 'u': buf.append(date.dayOfWeek().get()); break; case 'V': // TODO: fix week-of-year number leftPad(date.weekOfWeekyear().get(), '0', 2, buf); break; case 'v': // Equivalent of %e-%b-%Y leftPad(date.dayOfMonth().get(), ' ', 2, buf); buf.append('-'); buf.append(date.monthOfYear().getAsShortText()); buf.append('-'); buf.append(date.getYear()); break; case 'W': // TODO: fix week-of-year number break; case 'w': buf.append(date.dayOfWeek().get()); break; case 'X': formatAggregate(DateTimeAggregate.HHMMSSP, locale, date, buf); break; case 'x': formatAggregate(DateTimeAggregate.MMDDYYYY, locale, date, buf); break; case 'Y': buf.append(date.getYear()); break; case 'y': leftPad(date.getYearOfCentury(), '0', 2, buf); break; case 'Z': // Note: Joda's nameKey happens to be the same as the shortName. Making // this change to workaround Joda https://github.com/JodaOrg/joda-time/issues/288 buf.append(zone.getNameKey(date.getMillis())); break; case 'z': int offset = date.getZone().getOffset(instant) / 60000; int hours = (int) Math.floor(offset / 60); int minutes = (hours * 60) - offset; if (offset < 0) { buf.append('-'); } leftPad(Math.abs(hours), '0', 2, buf); leftPad(Math.abs(minutes), '0', 2, buf); break; default: // no match, emit literals. buf.append(c1).append(c2); } index++; } }
From source file:com.userweave.domain.util.InvoiceNumberProvider.java
License:Open Source License
public static String getNextNumber(int next) { DateTime today = new DateTime(); return String.format("UM%02d%02d%04d", today.getYearOfCentury(), today.getMonthOfYear(), next); }
From source file:com.userweave.domain.util.InvoiceNumberProvider.java
License:Open Source License
public static String getNextNumberPrefix() { DateTime today = new DateTime(); return String.format("UM%02d%02d", today.getYearOfCentury(), today.getMonthOfYear()); }
From source file:de.dmarcini.submatix.android4.full.comm.BlueThoothComService.java
License:Open Source License
/** * /*ww w .j ava 2 s . c o m*/ * schreibe Datum und Zeit in das Gert * * Project: SubmatixBTLoggerAndroid Package: de.dmarcini.submatix.android4.comm * * * Stand: 27.10.2013 * * @param cf * @param dTime * @throws FirmwareNotSupportetException * */ public void writeDateTimeToDevice( SPX42Config cf, DateTime dTime ) throws FirmwareNotSupportetException { String kdoString; // // if( !cf.isFirmwareSupported() ) { Log.e( TAG, "firmware not supportet for write settings!" ); throw new FirmwareNotSupportetException( "write datetime to device" ); } if( cf.canSetDateTime() ) { // // Setze das Zeit und Datum als Kommandostring zusammen // kdoString = String.format( "%s~%x:%02x:%02x:%02x:%02x:%02x%s", ProjectConst.STX, ProjectConst.SPX_DATETIME, dTime.getHourOfDay(), dTime.getMinuteOfHour(), dTime.getDayOfMonth(), dTime.getMonthOfYear(), dTime.getYearOfCentury(), ProjectConst.ETX ); { if( ApplicationDEBUG.DEBUG ) Log.d( TAG, "writeDateTimeToDevice()...send <" + kdoString + "> (DATETIME)" ); } this.writeToDevice( kdoString ); } else { if( ApplicationDEBUG.DEBUG ) Log.d( TAG, "writeDateTimeToDevice()...Firmware not support <set datetime> yet" ); } }
From source file:de.dmarcini.submatix.pclogger.comm.BTCommunication.java
License:Open Source License
@Override public void writeDateTimeToDevice(DateTime dTime) { String kdoString;//from ww w .j a v a 2 s .c o m // if (isConnected) { // // Setze das Zeit und Datum als Kommandostring zusammen // kdoString = String.format("%s~%x:%02x:%02x:%02x:%02x:%02x%s", ProjectConst.STX, ProjectConst.SPX_DATETIME, dTime.getHourOfDay(), dTime.getMinuteOfHour(), dTime.getDayOfMonth(), dTime.getMonthOfYear(), dTime.getYearOfCentury(), ProjectConst.ETX); { lg.debug("writeDateTimeToDevice()...send <" + kdoString + "> (DATETIME)"); } this.writeToDevice(kdoString); } }
From source file:org.mayocat.shop.invoicing.internal.DefaultInvoicingService.java
License:Mozilla Public License
@Override public synchronized InvoiceNumber getOrCreateInvoiceNumber(Order order) throws InvoicingException { this.dao.begin(); InvoiceNumber existing = this.dao.findForOrderId(order.getId()); if (existing != null) { this.dao.commit(); return existing; }/*from w w w .j av a 2 s. c o m*/ DateTime dateTime = new DateTime(); int weekOfYear = dateTime.getWeekOfWeekyear(); int year = dateTime.getYearOfCentury(); String prefix = String.format("%02d%02d", year, weekOfYear); Integer previousCountForPrefix = this.dao.getCountForPrefix(prefix); String number = prefix + String.format("%03d", ++previousCountForPrefix); InvoiceNumber generated = new InvoiceNumber(order.getId(), number, new Date()); this.dao.createInvoiceNumber(generated); this.dao.commit(); return generated; }
From source file:org.ojbc.web.portal.controllers.helpers.DateTimePropertyEditor.java
License:RPL License
@Override public void setAsText(String text) throws IllegalArgumentException { if (StringUtils.isBlank(text)) { return;//from w w w . j a va 2s. c o m } try { String[] tokens = text.trim().split("/"); //We defensively check for a two digit year date here even though the UI should never let it through //If date entered is of the format mm/dd/yy, and yy > current year + 10, then assume the prior century String yearAsString = tokens[2]; if ((yearAsString.length() != 2) && (yearAsString.length() != 4)) { throw new IllegalArgumentException("Unable to parse date"); } DateTime currentDate = new DateTime(); if (yearAsString.length() == 2) { int lastTwoDigitsOfCurrentYear = currentDate.getYearOfCentury(); int lastTwoDigitsOfEnteredDate = Integer.valueOf(yearAsString); if (lastTwoDigitsOfEnteredDate > lastTwoDigitsOfCurrentYear + 10) { yearAsString = String.valueOf(currentDate.minusYears(100).getCenturyOfEra()) + yearAsString; } else { yearAsString = String.valueOf(currentDate.getCenturyOfEra()) + yearAsString; } } this.setValue(new DateTime(Integer.valueOf(yearAsString), Integer.valueOf(tokens[0]), Integer.valueOf(tokens[1]), 0, 0, 0, 0)); } catch (RuntimeException ex) { throw new IllegalArgumentException("Unable to parse date"); } }