Java Code Examples for java.time.Month#getValue()

The following examples show how to use java.time.Month#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtraDateStrings.java    From LGoodDatePicker with MIT License 6 votes vote down vote up
/**
 * getStandaloneMonthName, This returns a "standalone version" month name for the specified
 * month, in the specified locale. In some languages, including Russian and Czech, the
 * standalone version of the month name is different from the version of the month name you
 * would use as part of a full date. (Is different from the formatting version).
 *
 * This tries to get the standalone version first. If no mapping is found for a standalone
 * version (Presumably because the supplied language has no standalone version), then this will
 * return the formatting version of the month name.
 */
private static String getStandaloneMonthName(Month month, Locale locale, boolean capitalize,
        boolean shortVersion) {
    // Attempt to get the standalone version of the month name.
    TextStyle style = (shortVersion) ? TextStyle.SHORT_STANDALONE : TextStyle.FULL_STANDALONE;
    String monthName = month.getDisplayName(style, locale);
    String monthNumber = "" + month.getValue();
    // If no mapping was found, then get the "formatting version" of the month name.
    if (monthName.equals(monthNumber)) {
        DateFormatSymbols dateSymbols = DateFormatSymbols.getInstance(locale);
        if (shortVersion) {
            monthName = dateSymbols.getShortMonths()[month.getValue() - 1];
        } else {
            monthName = dateSymbols.getMonths()[month.getValue() - 1];
        }
    }
    // If needed, capitalize the month name.
    if ((capitalize) && (monthName != null) && (monthName.length() > 0)) {
        monthName = monthName.substring(0, 1).toUpperCase(locale) + monthName.substring(1);
    }
    return monthName;
}
 
Example 2
Source File: ExtraDateStrings.java    From LGoodDatePicker with MIT License 6 votes vote down vote up
/**
 * getFormattingMonthName, This returns a "formatting version" month name for the specified
 * month, in the specified locale. In some languages, including Russian and Czech, the
 * standalone version of the month name is different from the version of the month name you
 * would use as part of a full date. (Is different from the formatting version).
 */
private static String getFormattingMonthName(Month month, Locale locale, boolean capitalize,
        boolean shortVersion) {
    // Get the "formatting version" of the month name.
    DateFormatSymbols dateSymbols = DateFormatSymbols.getInstance(locale);
    String monthName;
    if (shortVersion) {
        monthName = dateSymbols.getShortMonths()[month.getValue() - 1];
    } else {
        monthName = dateSymbols.getMonths()[month.getValue() - 1];
    }
    // If needed, capitalize the month name.
    if ((capitalize) && (monthName != null) && (monthName.length() > 0)) {
        monthName = monthName.substring(0, 1).toUpperCase(locale) + monthName.substring(1);
    }
    return monthName;
}
 
Example 3
Source File: Iso8601MonthMonthTypeDescriptor.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
@Override
public <X> X unwrap(Month value, Class<X> type, WrapperOptions options) {
    if (value == null) {
        return null;
    }
    if (Number.class.isAssignableFrom(type)) {
        return (X) (Number) value.getValue();
    }
    throw unknownUnwrap(type);
}
 
Example 4
Source File: LocalDateIMMDateCalculator.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
private LocalDate calculateIMMMonth(final boolean requestNextIMM, final LocalDate startDate, final Month month) {
    int monthOffset;
    LocalDate date = startDate;
    switch (month) {
    case MARCH:
    case JUNE:
    case SEPTEMBER:
    case DECEMBER:
        final LocalDate immDate = calculate3rdWednesday(date);
        if (requestNextIMM && !date.isBefore(immDate)) {
            date = date.plusMonths(MONTHS_IN_QUARTER);
        } else if (!requestNextIMM && !date.isAfter(immDate)) {
            date = date.minusMonths(MONTHS_IN_QUARTER);
        }
        break;

    default:
        if (requestNextIMM) {
            monthOffset = (MONTH_IN_YEAR - month.getValue()) % MONTHS_IN_QUARTER;
            date = date.plusMonths(monthOffset);
        } else {
            monthOffset = month.getValue() % MONTHS_IN_QUARTER;
            date = date.minusMonths(monthOffset);
        }
        break;
    }
    return date;
}
 
Example 5
Source File: MailingStatisticForm.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setMonth(Month month) {
    this.month = month.getValue()-1;
}
 
Example 6
Source File: IntegerColumnMonthMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public String toNonNullString(Month value) {
    return "" + value.getValue();
}
 
Example 7
Source File: IntegerColumnMonthMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public Integer toNonNullValue(Month value) {
    return value.getValue();
}
 
Example 8
Source File: EnumsUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@ParameterizedTest
@EnumSource(Month.class)
void getValueForAMonth_IsAlwaysBetweenOneAndTwelve(Month month) {
    int monthNumber = month.getValue();
    assertTrue(monthNumber >= 1 && monthNumber <= 12);
}
 
Example 9
Source File: DateTimeExtensions.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the {@link java.time.Month} that is {@code months} months after this month.
 *
 * @param self   a Month
 * @param months the number of months move forward
 * @return the Month
 * @since 2.5.0
 */
public static Month plus(final Month self, int months) {
    int monthsPerYear = Month.values().length;
    int val = ((self.getValue() + months - 1) % monthsPerYear) + 1;
    return Month.of(val > 0 ? val : monthsPerYear + val);
}