Example usage for java.time LocalDate parse

List of usage examples for java.time LocalDate parse

Introduction

In this page you can find the example usage for java.time LocalDate parse.

Prototype

public static LocalDate parse(CharSequence text, DateTimeFormatter formatter) 

Source Link

Document

Obtains an instance of LocalDate from a text string using a specific formatter.

Usage

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testCreateRuleThrowsWhenNewRuleClashesWithExistingRules_ExistingNonRecurringNewRecurringSameDayOfWeekOverlappingNoExclusion()
        throws Exception {
    // If the new rule is recurring and there are any overlapping, non-recurring
    // existing rules after the new rule starts, then we have a clash, unless
    // the new rule has a relevant exclusion.

    // ARRANGE//from ww w. j  a v  a2s. c o m
    thrown.expect(Exception.class);
    thrown.expectMessage("Booking rule creation failed");

    // Set up a rule to create that clashes in required way with existing rules
    BookingRule clashingThursdayRule = new BookingRule(existingThursdayNonRecurringRule);
    clashingThursdayRule.setIsRecurring(true);

    // Move date to same day-of-week but to some date earlier than the existing
    // non-recurring rule.
    String existingDate = clashingThursdayRule.getBooking().getDate();
    String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusWeeks(1)
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    clashingThursdayRule.getBooking().setDate(newDate);

    // ACT
    doTestCreateRuleClashesOrNotWithExistingRule(clashingThursdayRule, true);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testCreateRuleDoesNotThrowWhenNewRuleDoesNotClashWithExistingRules_ExistingNonRecurringNewRecurringSameDayOfWeekOverlappingWithExclusion()
        throws Exception {
    // If the new rule is recurring and there are any overlapping, non-recurring
    // existing rules after the new rule starts, then we do not have a clash if
    // the new rule has a relevant exclusion. N.B. We allow exclusions at
    // creation time to support backup/restore.

    // ARRANGE/*from www . ja va 2s.c o  m*/

    // Set up a rule to create that clashes in required way with existing rules
    BookingRule nonClashingThursdayRule = new BookingRule(existingThursdayNonRecurringRule);
    nonClashingThursdayRule.setIsRecurring(true);

    // Move date to same day-of-week but to some date earlier than the existing
    // non-recurring rule.
    String existingDate = nonClashingThursdayRule.getBooking().getDate();
    String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusWeeks(1)
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    nonClashingThursdayRule.getBooking().setDate(newDate);

    // Add exclusion to new rule - so it becomes non-clashing
    nonClashingThursdayRule
            .setDatesToExclude(new String[] { existingThursdayNonRecurringRule.getBooking().getDate() });

    // ACT
    doTestCreateRuleClashesOrNotWithExistingRule(nonClashingThursdayRule, false);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testCreateRuleThrowsWhenNewRuleClashesWithExistingRules_ExistingNonRecurringNewRecurringSameDayOfWeekPartiallyOverlappingNoExclusion()
        throws Exception {
    // If the new rule is recurring and there are any overlapping, non-recurring
    // existing rules after the new rule starts, then we have a clash. N.B. This
    // tests where the court/time blocks overlap only partially.

    // ARRANGE// ww w  .  ja  va2 s  .  c om
    thrown.expect(Exception.class);
    thrown.expectMessage("Booking rule creation failed");

    // Set up a rule to create that clashes in required way with existing rules
    BookingRule clashingThursdayRule = new BookingRule(existingThursdayNonRecurringRule);
    clashingThursdayRule.setIsRecurring(true);

    // Move date to same day-of-week but to some date earlier than the existing
    // non-recurring rule.
    String existingDate = clashingThursdayRule.getBooking().getDate();
    String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusWeeks(1)
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    clashingThursdayRule.getBooking().setDate(newDate);

    // Tweak court so that overlap is partial only
    clashingThursdayRule.getBooking().setCourt(clashingThursdayRule.getBooking().getCourt()
            + clashingThursdayRule.getBooking().getCourtSpan() - 1);

    // ACT
    doTestCreateRuleClashesOrNotWithExistingRule(clashingThursdayRule, true);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testCreateRuleDoesNotThrowWhenNewRuleDoesNotClashWithExistingRules_ExistingNonRecurringInPastNewRecurringSameDayOfWeekOverlappingNoExclusion()
        throws Exception {
    // This checks that a new recurring rule does not clash with an existing
    // non-recurring one if that existing rule has a date before the new
    // recurring rule starts.

    // ARRANGE/*from  ww w. j ava  2  s . c  o m*/
    // Set up a rule to create that does not clash with existing rules
    BookingRule nonClashingThursdayRule = new BookingRule(existingThursdayNonRecurringRule);
    nonClashingThursdayRule.setIsRecurring(true);

    // Tweak date to be ahead of the existing non-recurring rule
    String existingDate = nonClashingThursdayRule.getBooking().getDate();
    String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).plusWeeks(1)
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    nonClashingThursdayRule.getBooking().setDate(newDate);

    // ACT
    doTestCreateRuleClashesOrNotWithExistingRule(nonClashingThursdayRule, false);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testCreateRuleDoesNotThrowWhenNewRuleDoesNotClashWithExistingRules_ExistingNonRecurringNewRecurringDifferentDayOfWeekOverlapping()
        throws Exception {
    // Tests case where we would have a clash if the days-of-the-week agreed -
    // but they don't, so should not clash.

    // ARRANGE// w w w  .j  a va  2s.c om
    // Set up a rule to create that does not clash with existing rules
    BookingRule nonClashingWednesdayRule = new BookingRule(existingThursdayNonRecurringRule);
    nonClashingWednesdayRule.setIsRecurring(true);

    // Move date to a different day of the week
    String existingDate = nonClashingWednesdayRule.getBooking().getDate();
    String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).plusDays(6)
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    nonClashingWednesdayRule.getBooking().setDate(newDate); // Wednesday

    // ACT
    doTestCreateRuleClashesOrNotWithExistingRule(nonClashingWednesdayRule, false);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testCreateRuleThrowsWhenNewRuleClashesWithExistingRules_ExistingRecurringNewRecurringSameDayOfWeekOverlapping()
        throws Exception {
    // Always clash if both new and existing rules are recurring and
    // overlapping.

    // ARRANGE/*from  w w w . ja  va 2s. c  o m*/
    thrown.expect(Exception.class);
    thrown.expectMessage("Booking rule creation failed");

    // Set up a rule to create that clashes in required way with existing rules
    BookingRule clashingFridayRule = new BookingRule(existingFridayRecurringRuleWithoutExclusions);
    // Move date to same day-of-week but to some date later than the existing
    // non-recurring rule - should make no difference.
    String existingDate = clashingFridayRule.getBooking().getDate();
    String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).plusWeeks(100)
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    clashingFridayRule.getBooking().setDate(newDate);

    // ACT
    doTestCreateRuleClashesOrNotWithExistingRule(clashingFridayRule, true);
}

From source file:org.silverpeas.core.util.DateUtil.java

public static LocalDate parseFromLucene(String date) {
    if (date == null) {
        return null;
    }//from   ww  w  .  ja v  a 2 s .co m
    return LocalDate.parse(date, LUCENE_FORMATTER);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testCreateRuleDoesNotThrowWhenNewRuleDoesNotClashWithExistingRules_ExistingRecurringNewNonRecurringSameDayOfWeekOverlappingExclusions()
        throws Exception {
    // If existing rule is recurring and new rule is non-recurring for
    // overlapping court/time and same day-of-the-week for a date in the future
    // and there is a relevant exclusion, then we do not have a clash. This
    // checks that when the relevant exclusion is not the first exclusion in the
    // exclusions array, it is still respected.

    // ARRANGE//from   w  ww  .  ja va 2  s  .c om
    // Set up a rule to create that does not clash with existing rules
    BookingRule nonClashingSaturdayRule = new BookingRule(existingSaturdayRecurringRuleWithExclusion);
    nonClashingSaturdayRule.setIsRecurring(false);
    nonClashingSaturdayRule.setDatesToExclude(new String[0]);

    // Move date to equal the second exclusion on the existing recurring rule
    // Add second exclusion:
    String existingExclusion = existingSaturdayRecurringRuleWithExclusion.getDatesToExclude()[0];
    String newExclusion = LocalDate.parse(existingExclusion, DateTimeFormatter.ofPattern("yyyy-MM-dd"))
            .plusWeeks(12).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

    String[] newExcludeDates = new String[] { existingSaturdayRecurringRuleWithExclusion.getDatesToExclude()[0],
            newExclusion };
    existingSaturdayRecurringRuleWithExclusion.setDatesToExclude(newExcludeDates);

    nonClashingSaturdayRule.getBooking().setDate(newExcludeDates[1]);

    // ACT
    doTestCreateRuleClashesOrNotWithExistingRule(nonClashingSaturdayRule, false);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testCreateRuleThrowsWhenNewRuleClashesWithExistingRules_ExistingRecurringNewNonRecurringSameDayOfWeekOverlappingNoExclusion()
        throws Exception {
    // If existing rule is recurring and new rule is non-recurring for
    // overlapping court/time and same day-of-the-week for a date in the future
    // and there is no relevant exclusion - we have a clash.

    // ARRANGE/*from  w ww .  ja va2  s .c o  m*/
    thrown.expect(Exception.class);
    thrown.expectMessage("Booking rule creation failed");

    // Set up a rule to create that clashes in required way with existing rules
    BookingRule clashingFridayRule = new BookingRule(existingFridayRecurringRuleWithoutExclusions);
    clashingFridayRule.setIsRecurring(false);
    // Move date to same day-of-week but to some future date
    String existingDate = clashingFridayRule.getBooking().getDate();
    String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).plusWeeks(12)
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    clashingFridayRule.getBooking().setDate(newDate);

    // ACT
    doTestCreateRuleClashesOrNotWithExistingRule(clashingFridayRule, true);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testCreateRuleDoesNotThrowWhenNewRuleDoesNotClashWithExistingRules_ExistingRecurringNewNonRecurringBeforeStartSameDayOfWeekOverlappingNoExclusion()
        throws Exception {
    // If existing rule is recurring and new rule is non-recurring for
    // overlapping court/time and same day-of-the-week, but for a date both not
    // in the past and before the recurring rule starts, we do not have a clash.

    // ARRANGE/*from w w w. j  av  a 2  s .co m*/

    // Set up a rule to create that avoids clash in required way with existing
    // rules
    BookingRule nonClashingFridayRule = new BookingRule(existingFridayRecurringRuleWithoutExclusions);
    nonClashingFridayRule.setIsRecurring(false);
    // Move date to one week earlier i.e. to before recurring rule starts
    String existingDate = nonClashingFridayRule.getBooking().getDate();
    String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusWeeks(1)
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    nonClashingFridayRule.getBooking().setDate(newDate);

    // ACT
    doTestCreateRuleClashesOrNotWithExistingRule(nonClashingFridayRule, false);
}