Class F_Instant_Add

java.lang.Object
com.ssgllc.fish.f.instant.F_Instant_Add

public class F_Instant_Add extends Object
Moment arithmetic, reached as add or subtract on an F_Instant.

The direction comes from which field you went through, so counts stay positive. Note the split in behaviour: minutes, hours, days and weeks add fixed durations, while months and years are resolved as calendar shifts in a zone - which is why those two take an optional zone id.

  • Constructor Details

    • F_Instant_Add

      public F_Instant_Add(Instant instant, int dir)
  • Method Details

    • minutes

      public F_Instant minutes(int minutes)
      Moves the moment by a number of minutes. Reached as add to move forwards or subtract to move backwards, so the count is always positive.
      Parameters:
      minutes - the number of minutes to move
      Returns:
      the shifted moment, to continue the chain from

      Groovy example:
      f().instant.now().add.minutes(30).toIso()

      Returns:
      half an hour from now

      SpEL example:
      #f().instant.now().add.minutes(30).toIso()
    • hours

      public F_Instant hours(int hours)
      Moves the moment by a number of hours. Reached as add to move forwards or subtract to move backwards, so the count is always positive.
      Parameters:
      hours - the number of hours to move
      Returns:
      the shifted moment, to continue the chain from

      Groovy example:
      f().instant.now().subtract.hours(2).toIso()

      Returns:
      two hours ago

      SpEL example:
      #f().instant.now().subtract.hours(2).toIso()
    • days

      public F_Instant days(int days)
      Moves the moment by a number of days. Reached as add to move forwards or subtract to move backwards, so the count is always positive. A day here is exactly 24 hours, so a shift across a daylight-saving boundary moves the local wall-clock time by an hour.
      Parameters:
      days - the number of days to move
      Returns:
      the shifted moment, to continue the chain from

      Groovy example:
      f().instant.now().add.days(30).toIso()

      Returns:
      thirty days from now

      SpEL example:
      #f().instant.now().add.days(30).toIso()
    • weeks

      public F_Instant weeks(int weeks)
      Moves the moment by a number of weeks. Reached as add to move forwards or subtract to move backwards, so the count is always positive. A week here is exactly seven 24-hour days, with the same daylight-saving caveat as days.
      Parameters:
      weeks - the number of weeks to move
      Returns:
      the shifted moment, to continue the chain from

      Groovy example:
      f().instant.now().subtract.weeks(2).toIso()

      Returns:
      a fortnight ago

      SpEL example:
      #f().instant.now().subtract.weeks(2).toIso()
    • months

      public F_Instant months(int months)
      Moves the moment by a number of months, in the system default zone. Calendar months are not a fixed length, so this converts to local date-time, shifts, and converts back - keeping the local wall-clock time rather than adding a fixed duration. Use months(int, String) to pin the zone.
      Parameters:
      months - the number of months to move
      Returns:
      the shifted moment, to continue the chain from

      Groovy example:
      f().instant.now().add.months(6).toIso()

      Returns:
      six months from now

      SpEL example:
      #f().instant.now().add.months(6).toIso()
    • months

      public F_Instant months(int months, String timeZone)
      Moves the moment by a number of months, resolved in an explicit zone. Prefer this over months(int) wherever the answer must not depend on the server's zone.
      Parameters:
      months - the number of months to move
      timeZone - the zone id to resolve the shift in
      Returns:
      the shifted moment, to continue the chain from

      Groovy example:
      f().instant.of(entity.createdDate).add.months(1, "America/New_York").toIso()

      Returns:
      a calendar month later, as reckoned in New York

      SpEL example:
      #f().instant.of(entity.createdDate).add.months(1, "America/New_York").toIso()
    • years

      public F_Instant years(int years)
      Moves the moment by a number of years, in the system default zone. Resolved as a calendar shift, so 29 February becomes 28 February in a non-leap target year. Use years(int, String) to pin the zone.
      Parameters:
      years - the number of years to move
      Returns:
      the shifted moment, to continue the chain from

      Groovy example:
      f().instant.of(entity.birthDate).add.years(18).toIso()

      Returns:
      the eighteenth birthday

      SpEL example:
      #f().instant.of(entity.birthDate).add.years(18).toIso()
    • years

      public F_Instant years(int years, String timeZone)
      Moves the moment by a number of years, resolved in an explicit zone.
      Parameters:
      years - the number of years to move
      timeZone - the zone id to resolve the shift in
      Returns:
      the shifted moment, to continue the chain from

      Groovy example:
      f().instant.now().subtract.years(1, "UTC").toIso()

      Returns:
      a year ago, reckoned in UTC

      SpEL example:
      #f().instant.now().subtract.years(1, "UTC").toIso()