Example usage for org.joda.time DateTime minuteOfHour

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

Introduction

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

Prototype

public Property minuteOfHour() 

Source Link

Document

Get the minute of hour field property which provides access to advanced functionality.

Usage

From source file:com.chiorichan.plugin.lua.api.OSAPI.java

License:Mozilla Public License

@Override
void initialize() {
    // Push a couple of functions that override original Lua API functions or
    // that add new functionality to it.
    lua.getGlobal("os");

    // Custom os.clock() implementation returning the time the computer has
    // been actively running, instead of the native library...
    lua.pushJavaFunction(new JavaFunction() {
        @Override//  www .j av a  2s. c o m
        public int invoke(LuaState lua) {
            lua.pushNumber(System.currentTimeMillis());
            return 1;
        }
    });
    lua.setField(-2, "clock");

    lua.pushJavaFunction(new JavaFunction() {
        @Override
        public int invoke(LuaState lua) {
            String format = lua.getTop() > 0 && lua.isString(1) ? lua.toString(1) : "%d/%m/%y %H:%M:%S";
            long time = (long) (lua.getTop() > 1 && lua.isNumber(2) ? lua.toNumber(2) * 1000 / 60 / 60
                    : System.currentTimeMillis());
            DateTime dt = new DateTime(time);
            if (format == "*t") {
                lua.newTable(0, 8);
                lua.pushInteger(dt.year().get());
                lua.setField(-2, "year");
                lua.pushInteger(dt.monthOfYear().get());
                lua.setField(-2, "month");
                lua.pushInteger(dt.dayOfMonth().get());
                lua.setField(-2, "day");
                lua.pushInteger(dt.hourOfDay().get());
                lua.setField(-2, "hour");
                lua.pushInteger(dt.minuteOfHour().get());
                lua.setField(-2, "min");
                lua.pushInteger(dt.secondOfMinute().get());
                lua.setField(-2, "sec");
                lua.pushInteger(dt.dayOfWeek().get());
                lua.setField(-2, "wday");
                lua.pushInteger(dt.dayOfYear().get());
                lua.setField(-2, "yday");
            } else
                lua.pushString(dt.toString(DateTimeFormat.forPattern(format)));
            return 1;
        }
    });
    lua.setField(-2, "date");

    /*
     * // Date formatting function.
     * lua.pushScalaFunction(lua => {
     * val format =
     * if (lua.getTop > 0 && lua.isString(1)) lua.toString(1)
     * else "%d/%m/%y %H:%M:%S"
     * val time =
     * if (lua.getTop > 1 && lua.isNumber(2)) lua.toNumber(2) * 1000 / 60 / 60
     * else machine.worldTime + 5000
     * 
     * val dt = GameTimeFormatter.parse(time)
     * def fmt(format: String) {
     * if (format == "*t") {
     * lua.newTable(0, 8)
     * lua.pushInteger(dt.year)
     * lua.setField(-2, "year")
     * lua.pushInteger(dt.month)
     * lua.setField(-2, "month")
     * lua.pushInteger(dt.day)
     * lua.setField(-2, "day")
     * lua.pushInteger(dt.hour)
     * lua.setField(-2, "hour")
     * lua.pushInteger(dt.minute)
     * lua.setField(-2, "min")
     * lua.pushInteger(dt.second)
     * lua.setField(-2, "sec")
     * lua.pushInteger(dt.weekDay)
     * lua.setField(-2, "wday")
     * lua.pushInteger(dt.yearDay)
     * lua.setField(-2, "yday")
     * }
     * else {
     * lua.pushString(GameTimeFormatter.format(format, dt))
     * }
     * }
     * 
     * // Just ignore the allowed leading '!', Minecraft has no time zones...
     * if (format.startsWith("!"))
     * fmt(format.substring(1))
     * else
     * fmt(format)
     * 1
     * })
     * lua.setField(-2, "date")
     * 
     * // Return ingame time for os.time().
     * lua.pushScalaFunction(lua => {
     * if (lua.isNoneOrNil(1)) {
     * // Game time is in ticks, so that each day has 24000 ticks, meaning
     * // one hour is game time divided by one thousand. Also, Minecraft
     * // starts days at 6 o'clock, versus the 1 o'clock of timestamps so we
     * // add those five hours. Thus:
     * // timestamp = (time + 5000) * 60[kh] * 60[km] / 1000[s]
     * lua.pushNumber((machine.worldTime + 5000) * 60 * 60 / 1000)
     * }
     * else {
     * def getField(key: String, d: Int) = {
     * lua.getField(-1, key)
     * val res = lua.toIntegerX(-1)
     * lua.pop(1)
     * if (res == null)
     * if (d < 0) throw new Exception("field '" + key + "' missing in date table")
     * else d
     * else res: Int
     * }
     * 
     * lua.checkType(1, LuaType.TABLE)
     * lua.setTop(1)
     * 
     * val sec = getField("sec", 0)
     * val min = getField("min", 0)
     * val hour = getField("hour", 12)
     * val mday = getField("day", -1)
     * val mon = getField("month", -1)
     * val year = getField("year", -1)
     * 
     * GameTimeFormatter.mktime(year, mon, mday, hour, min, sec) match {
     * case Some(time) => lua.pushNumber(time)
     * case _ => lua.pushNil()
     * }
     * }
     * 1
     * })
     * lua.setField(-2, "time")
     */
    // Pop the os table.
    lua.pop(1);
}

From source file:com.enonic.cms.core.search.query.factory.FilterQueryBuilderFactory.java

License:Open Source License

private FilterBuilder buildContentPublishedAtFilter(final DateTime dateTime) {
    final ReadableDateTime dateTimeRoundedDownToNearestMinute = toUTCTimeZone(
            dateTime.minuteOfHour().roundFloorCopy());

    final RangeFilterBuilder publishFromFilter = FilterBuilders
            .rangeFilter(//from   w  ww. j a  v  a  2s. c  o  m
                    QueryFieldFactory.resolveQueryField(PUBLISH_FROM_FIELDNAME).getFieldNameForDateQueries())
            .lte(dateTimeRoundedDownToNearestMinute);

    final MissingFilterBuilder publishToMissing = FilterBuilders.missingFilter(
            QueryFieldFactory.resolveQueryField(PUBLISH_TO_FIELDNAME).getFieldNameForDateQueries());
    final RangeFilterBuilder publishToGTDate = FilterBuilders
            .rangeFilter(QueryFieldFactory.resolveQueryField(PUBLISH_TO_FIELDNAME).getFieldNameForDateQueries())
            .gt(dateTimeRoundedDownToNearestMinute);
    final OrFilterBuilder publishToFilter = FilterBuilders.orFilter(publishToMissing, publishToGTDate);

    final AndFilterBuilder filter = FilterBuilders.andFilter(publishFromFilter, publishToFilter);
    return filter;
}

From source file:com.enonic.cms.domain.content.index.translator.ContentQueryTranslator.java

License:Open Source License

protected void applyContentPublishedAtFilter(SelectBuilder hqlQuery, DateTime dateTime) {
    if (dateTime != null) {
        DateTime dateTimeRoundedDownToNearestMinute = dateTime.minuteOfHour().roundFloorCopy();

        if ((this.dialect != null) && this.dialect.isInlineTimestampForSpeed()) {
            hqlQuery.addFilter("AND", "x.contentPublishFrom <= "
                    + this.dialect.formatTimestamp(dateTimeRoundedDownToNearestMinute.getMillis()));
            hqlQuery.addFilter("AND", "(x.contentPublishTo IS null OR x.contentPublishTo > "
                    + this.dialect.formatTimestamp(dateTimeRoundedDownToNearestMinute.getMillis()) + ")");
        } else {// www .  j  a  v a 2  s . c om
            hqlQuery.addFilter("AND", "x.contentPublishFrom <= :publishFromDate");
            hqlQuery.addFilter("AND", "(x.contentPublishTo IS null OR x.contentPublishTo > :publishToDate)");
            parameters.put("publishFromDate", dateTimeRoundedDownToNearestMinute.toDate());
            parameters.put("publishToDate", dateTimeRoundedDownToNearestMinute.toDate());
        }
    }
}

From source file:com.ofalvai.bpinfo.util.UiUtils.java

License:Apache License

/**
 * Transforms the start and end timestamps into a human-friendly readable string,
 * with special replacements for special dates, times, and the API's strange notations.
 * @param context Context/*from   www .  j  a  va 2  s .  c o m*/
 * @param startTimestamp Start of the alert in seconds since the UNIX epoch
 * @param endTimestamp   End of the alert in seconds since the UNIX epoch
 * @return  A string in the format of [startdate] [starttime] [separator] [enddate] [endtime]
 */
@NonNull
public static String alertDateFormatter(Context context, long startTimestamp, long endTimestamp) {
    DateTime startDateTime = new DateTime(startTimestamp * 1000L);
    DateTime endDateTime = new DateTime(endTimestamp * 1000L);
    LocalDate startDate = startDateTime.toLocalDate();
    LocalDate endDate = endDateTime.toLocalDate();

    DateTime today = new DateTime();
    LocalDate todayDate = new DateTime().toLocalDate();
    DateTime yesterday = today.minusDays(1);
    LocalDate yesterdayDate = yesterday.toLocalDate();
    DateTime tomorrow = today.plusDays(1);
    LocalDate tomorrowDate = tomorrow.toLocalDate();

    // Alert start, date part
    String startDateString;
    if (startDate.equals(todayDate)) {
        // Start day is today, replacing month and day with today string
        startDateString = context.getString(R.string.date_today) + " ";
    } else if (startDate.year().get() < today.year().get()) {
        // The start year is less than the current year, displaying the year too
        startDateString = Config.FORMATTER_DATE_YEAR.print(startDateTime);
    } else if (startDate.equals(yesterdayDate)) {
        startDateString = context.getString(R.string.date_yesterday) + " ";
    } else if (startDate.equals(tomorrowDate)) {
        startDateString = context.getString(R.string.date_tomorrow) + " ";
    } else {
        startDateString = Config.FORMATTER_DATE.print(startDateTime);
    }

    // Alert start, time part
    String startTimeString;
    if (startDateTime.hourOfDay().get() == 0 && startDateTime.minuteOfHour().get() == 0) {
        // The API marks "first departure" as 00:00
        startTimeString = context.getString(R.string.date_first_departure);
    } else {
        startTimeString = Config.FORMATTER_TIME.print(startDateTime);
    }

    // Alert end, date part
    String endDateString;
    if (endTimestamp == 0) {
        // The API marks "until further notice" as 0 (in UNIX epoch), no need to display date
        // (the replacement string is displayed as the time part, not the date)
        endDateString = " ";
    } else if (endDate.year().get() > today.year().get()) {
        // The end year is greater than the current year, displaying the year too
        endDateString = Config.FORMATTER_DATE_YEAR.print(endDateTime);
    } else if (endDate.equals(todayDate)) {
        // End  day is today, replacing month and day with today string
        endDateString = context.getString(R.string.date_today) + " ";
    } else if (endDate.equals(yesterdayDate)) {
        endDateString = context.getString(R.string.date_yesterday) + " ";
    } else if (endDate.equals(tomorrowDate)) {
        endDateString = context.getString(R.string.date_tomorrow) + " ";
    } else {
        endDateString = Config.FORMATTER_DATE.print(endDateTime);
    }

    // Alert end, time part
    String endTimeString;
    if (endTimestamp == 0) {
        // The API marks "until further notice" as 0 (in UNIX epoch)
        endTimeString = context.getString(R.string.date_until_revoke);
    } else if (endDateTime.hourOfDay().get() == 23 && endDateTime.minuteOfHour().get() == 59) {
        // The API marks "last departure" as 23:59
        endTimeString = context.getString(R.string.date_last_departure);
    } else {
        endTimeString = Config.FORMATTER_TIME.print(endDateTime);
    }

    return startDateString + startTimeString + Config.DATE_SEPARATOR + endDateString + endTimeString;
}

From source file:com.sap.dirigible.runtime.metrics.TimeUtils.java

License:Open Source License

private static DateTime dateTimeCeiling(DateTime dt, Period p) {
    if (p.getYears() != 0) {
        return dt.yearOfEra().roundCeilingCopy().minusYears(dt.getYearOfEra() % p.getYears());
    } else if (p.getMonths() != 0) {
        return dt.monthOfYear().roundCeilingCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
    } else if (p.getWeeks() != 0) {
        return dt.weekOfWeekyear().roundCeilingCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
    } else if (p.getDays() != 0) {
        return dt.dayOfMonth().roundCeilingCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
    } else if (p.getHours() != 0) {
        return dt.hourOfDay().roundCeilingCopy().minusHours(dt.getHourOfDay() % p.getHours());
    } else if (p.getMinutes() != 0) {
        return dt.minuteOfHour().roundCeilingCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
    } else if (p.getSeconds() != 0) {
        return dt.secondOfMinute().roundCeilingCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
    }// w  w  w. j a va2s .  c o  m
    return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

From source file:com.splicemachine.db.iapi.types.TruncateFunctionUtil.java

License:Apache License

private static DateTimeDataValue doTrunc(DataValueDescriptor dateVal, DataValueDescriptor truncValue,
        DateTimeDataValue truncd, boolean isTimestamp) throws StandardException {
    if (dateVal.isNull()) {
        return truncd;
    }// w  w  w.  j  a  v a  2 s  .  c  om
    DateTime realDT = dateVal.getDateTime();
    DateTime newDT;
    // DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
    switch (getTruncValue(truncValue)) {
    case YEAR:
    case YR:
        newDT = realDT.year().roundFloorCopy();
        break;

    case MONTH:
    case MON:
    case MO:
        newDT = realDT.monthOfYear().roundFloorCopy();
        break;

    case DAY:
        newDT = realDT.dayOfMonth().roundFloorCopy();
        break;

    case HOUR:
    case HR:
        if (!isTimestamp) {
            throw StandardException.newException(SQLState.LANG_TRUNCATE_WRONG_TRUNC_VALUE_FOR_DATE,
                    getTruncValue(truncValue).name());
        }
        newDT = realDT.hourOfDay().roundFloorCopy();
        break;

    case MINUTE:
    case MIN:
        if (!isTimestamp) {
            throw StandardException.newException(SQLState.LANG_TRUNCATE_WRONG_TRUNC_VALUE_FOR_DATE,
                    getTruncValue(truncValue).name());
        }
        newDT = realDT.minuteOfHour().roundFloorCopy();
        break;

    case SECOND:
    case SEC:
        if (!isTimestamp) {
            throw StandardException.newException(SQLState.LANG_TRUNCATE_WRONG_TRUNC_VALUE_FOR_DATE,
                    getTruncValue(truncValue).name());
        }
        newDT = realDT.secondOfMinute().roundFloorCopy();
        break;

    case MILLISECOND:
    case MILLI:
        if (!isTimestamp) {
            throw StandardException.newException(SQLState.LANG_TRUNCATE_WRONG_TRUNC_VALUE_FOR_DATE,
                    getTruncValue(truncValue).name());
        }
        newDT = realDT;
        break;

    default:
        throw StandardException.newException(SQLState.LANG_TRUNCATE_UNKNOWN_TRUNC_VALUE,
                (isTimestamp ? "TIMESTAMP" : "DATE"), getTruncValue(truncValue),
                stringifyValues(DateTruncValue.values()));
    }
    truncd.setValue(newDT);
    return truncd;
}

From source file:com.sqewd.os.maracache.api.utils.TimeUtils.java

License:Apache License

/**
 * Get the time bucket for the input date based on the Time Unit and Unit multiplier specified.
 *
 * @param dt         - Date time to bucket.
 * @param unit       - Time Unit//from  w  w  w . ja va2s .c  o m
 * @param multiplier - Unit multiplier.
 * @return
 */
public static DateTime bucket(DateTime dt, TimeUnit unit, int multiplier) {
    DateTime w = null;
    switch (unit) {
    case MILLISECONDS:
        int ms = (dt.getMillisOfSecond() / multiplier) * multiplier;
        w = dt.secondOfMinute().roundFloorCopy().plusMillis(ms);
        break;
    case SECONDS:
        int s = (dt.getSecondOfMinute() / multiplier) * multiplier;
        w = dt.minuteOfHour().roundFloorCopy().plusSeconds(s);
        break;
    case MINUTES:
        int m = (dt.getMinuteOfHour() / multiplier) * multiplier;
        w = dt.hourOfDay().roundFloorCopy().plusMinutes(m);
        break;
    case HOURS:
        int h = (dt.getHourOfDay() / multiplier) * multiplier;
        w = dt.dayOfYear().roundFloorCopy().plusHours(h);
        break;
    case DAYS:
        int d = (dt.getDayOfYear() / multiplier) * multiplier;
        // Need to subtract (1) as the start offset i
        if (dt.getDayOfYear() % multiplier == 0) {
            d -= 1;
        }
        w = dt.yearOfCentury().roundFloorCopy().plusDays(d);
        break;
    }
    return w;
}

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 ww w . ja  v  a 2 s  .  c  om*/
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.squarespace.template.plugins.PluginDateUtils.java

License:Apache License

private static void formatAggregate(DateTimeAggregate type, Locale locale, DateTime date, StringBuilder buf) {
    switch (type) {
    case FULL://from  w w w. jav  a2s  . com
        buf.append(date.dayOfWeek().getAsShortText(locale));
        buf.append(' ');
        leftPad(date.dayOfMonth().get(), '0', 2, buf);
        buf.append(' ');
        buf.append(date.monthOfYear().getAsShortText(locale));
        buf.append(' ');
        buf.append(date.year().get());
        buf.append(' ');
        leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), '0', 2, buf);
        buf.append(':');
        leftPad(date.minuteOfHour().get(), '0', 2, buf);
        buf.append(':');
        leftPad(date.secondOfMinute().get(), '0', 2, buf);
        buf.append(' ');
        buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "AM" : "PM");
        buf.append(' ');
        buf.append(date.getZone().getNameKey(date.getMillis()));
        break;

    case H240_M0:
        leftPad(date.get(DateTimeFieldType.clockhourOfDay()), '0', 2, buf);
        buf.append(':');
        leftPad(date.minuteOfHour().get(), '0', 2, buf);
        break;

    case HHMMSSP:
        leftPad(date.get(DateTimeFieldType.hourOfHalfday()), '0', 2, buf);
        buf.append(':');
        leftPad(date.getMinuteOfHour(), '0', 2, buf);
        buf.append(':');
        leftPad(date.getSecondOfMinute(), '0', 2, buf);
        buf.append(' ');
        buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "AM" : "PM");
        break;

    case MMDDYY:
        leftPad(date.getMonthOfYear(), '0', 2, buf);
        buf.append('/');
        leftPad(date.dayOfMonth().get(), '0', 2, buf);
        buf.append('/');
        leftPad(date.yearOfCentury().get(), '0', 2, buf);
        break;

    case MMDDYYYY:
        leftPad(date.getMonthOfYear(), '0', 2, buf);
        buf.append('/');
        leftPad(date.dayOfMonth().get(), '0', 2, buf);
        buf.append('/');
        buf.append(date.getYear());
        break;

    case YYYYMMDD:
        buf.append(date.year().get());
        buf.append('-');
        leftPad(date.monthOfYear().get(), '0', 2, buf);
        buf.append('-');
        leftPad(date.dayOfMonth().get(), '0', 2, buf);
        break;

    default:
        break;
    }
}

From source file:com.tikal.tallerWeb.modelo.alerta.RangoAlertaVerificacion.java

License:Apache License

private DateTime armaFechaRangoIzquierdo(int mes, int yearSwift) {
    DateTime r = new DateTime();
    r = new DateTime(r.getYear() + yearSwift, mes, r.dayOfMonth().getMinimumValue(),
            r.hourOfDay().getMinimumValue(), r.minuteOfHour().getMinimumValue(),
            r.secondOfMinute().getMinimumValue(), r.millisOfSecond().getMinimumValue(), r.getZone());
    r = r.minusDays(diasAntesDelMes);/*from w ww  .j  a v a2s . c o  m*/
    return r;
}