Java Code Examples for java.time.MonthDay#atYear()

The following examples show how to use java.time.MonthDay#atYear() . 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: NextHolidayAdjuster.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Override
public Temporal adjustInto(Temporal temporal) {

	MonthDay currentMonthDay = MonthDay.from(temporal);
	int year = temporal.get(ChronoField.YEAR);
	
	for (MonthDay element : COMPANY_HOLIDAYS) {
		if (currentMonthDay.isBefore(element)) {
			return element.atYear(year);
		}
	}
	
	// if it hasn't been returned, then return the first element
	return COMPANY_HOLIDAYS.get(0).atYear(year + 1);
}
 
Example 2
Source File: TCKMonthDay.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 3
Source File: TCKMonthDay.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 4
Source File: TCKMonthDay.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 5
Source File: TCKMonthDay.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 6
Source File: TCKMonthDay.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 7
Source File: StatementLine.java    From banking-swift-messages-java with MIT License 4 votes vote down vote up
public static StatementLine of(GeneralField field) throws FieldNotationParseException {

        Preconditions.checkArgument(field.getTag().equals(FIELD_TAG_61), "unexpected field tag '%s'", field.getTag());

        List<String> subFields = SWIFT_NOTATION.parse(field.getContent());

        LocalDate valueDate = LocalDate.parse(subFields.get(0), VALUE_DATE_FORMATTER);
        LocalDate entryDate = null;
        // calculate entry date
        if (subFields.get(1) != null) {
            MonthDay entryMonthDay = MonthDay.parse(subFields.get(1), ENTRY_DATE_FORMATTER);
            // calculate entry year
            int entryYear = entryMonthDay.getMonthValue() >= valueDate.getMonthValue()
                    ? valueDate.getYear()
                    : valueDate.getYear() + 1;
            entryDate = entryMonthDay.atYear(entryYear);
        }
        DebitCreditType debitCreditType;
        DebitCreditMark debitCreditMark;
        String foundsCode;
        //// due to ambiguous format notation fo field 3 & 4 (2a[1!a]) it need some extra logic
        // if field 3 starts with 'R' it is a two letter mark 'RC' or 'RD' and everything is fine
        String capitalCode = subFields.get(2);
        if (capitalCode.startsWith("R")) {
            debitCreditType = DebitCreditType.REVERSAL;
            debitCreditMark = DebitCreditMark.ofFieldValue(capitalCode.substring(1, 2));
            foundsCode = subFields.get(3);
        }
        // if field 3 does not start with 'R' it is a one letter mark 'C' or 'D'
        // in this case optional field 4 can be part of field 3
        else {
            debitCreditType = DebitCreditType.REGULAR;
            debitCreditMark = DebitCreditMark.ofFieldValue(capitalCode.substring(0, 1));
            foundsCode = capitalCode.length() > 1 ? capitalCode.substring(1, 2) : null;
            // ensure 'Funds Code' field is unset
            if (subFields.get(3) != null) {
                throw new IllegalStateException("Field " + FIELD_TAG_61 + ": Founds Code already set");
            }
        }

        BigDecimal amount = SwiftDecimalFormatter.parse(subFields.get(4));
        TransactionTypeIdentificationCode transactionTypeIdentificationCode = TransactionTypeIdentificationCode.of(subFields.get(5) + subFields.get(6));
        String referenceForAccountOwner = subFields.get(7);
        String referenceForBank = subFields.get(8);
        String supplementaryDetails = subFields.get(9);

        return new StatementLine(
                valueDate,
                entryDate,
                debitCreditType,
                debitCreditMark,
                amount,
                foundsCode,
                transactionTypeIdentificationCode,
                referenceForAccountOwner,
                referenceForBank,
                supplementaryDetails);
    }
 
Example 8
Source File: TCKMonthDay.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 9
Source File: TCKMonthDay.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 10
Source File: TCKMonthDay.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 11
Source File: TCKMonthDay.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 12
Source File: TCKMonthDay.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 13
Source File: TCKMonthDay.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 14
Source File: TCKMonthDay.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 15
Source File: TCKMonthDay.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 16
Source File: TCKMonthDay.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
Example 17
Source File: DateTimeExtensions.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a {@link java.time.LocalDate} of this month/day and the provided year.
 *
 * @param self a MonthDay
 * @param year a year
 * @return a LocalDate
 * @since 2.5.0
 */
public static LocalDate leftShift(final MonthDay self, int year) {
    return self.atYear(year);
}