Class DateService

  • All Implemented Interfaces:
    IDateService

    public class DateService
    extends java.lang.Object
    implements IDateService
    Service concerning the date.
    Author:
    Andi Hotz, (c) Sahits GmbH, 2016 Created on May 15, 2016
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Date date  
    • Constructor Summary

      Constructors 
      Constructor Description
      DateService()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getAge​(java.time.LocalDateTime birthDate)
      Calculate the age.
      double getPercentageBetweenDates​(java.time.LocalDateTime start, java.time.LocalDateTime end)
      Calculate the percentage of days passed between the start and end date.
      boolean isPast​(java.time.LocalDateTime date)
      Check if a date lies in the past.
      boolean isSameDay​(java.time.LocalDateTime date1, java.time.LocalDateTime date2)
      Check if two dates represent the same day
      boolean isToday​(java.time.LocalDateTime date)
      Check if the date is today.
      int toDaysCiel​(long milliseconds)
      Calculate the duration of milliseconds to ingame days and round up to the next full day.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • date

        @Autowired
        private Date date
    • Constructor Detail

      • DateService

        public DateService()
    • Method Detail

      • isSameDay

        public boolean isSameDay​(java.time.LocalDateTime date1,
                                 java.time.LocalDateTime date2)
        Description copied from interface: IDateService
        Check if two dates represent the same day
        Specified by:
        isSameDay in interface IDateService
        Parameters:
        date1 - first date to compair
        date2 - second date to compair
        Returns:
        true if both dates are on the same day
      • isToday

        public boolean isToday​(java.time.LocalDateTime date)
        Description copied from interface: IDateService
        Check if the date is today.
        Specified by:
        isToday in interface IDateService
        Parameters:
        date - to chack against the current date
        Returns:
        true if date is on the same day as current date
      • isPast

        public boolean isPast​(java.time.LocalDateTime date)
        Description copied from interface: IDateService
        Check if a date lies in the past.
        Specified by:
        isPast in interface IDateService
        Parameters:
        date - to be checked.
        Returns:
        true if the date is before the current game date
      • getAge

        public int getAge​(java.time.LocalDateTime birthDate)
        Description copied from interface: IDateService
        Calculate the age.
        Specified by:
        getAge in interface IDateService
        Parameters:
        birthDate - from which to calculate the age
        Returns:
        age in years
      • getPercentageBetweenDates

        public double getPercentageBetweenDates​(java.time.LocalDateTime start,
                                                java.time.LocalDateTime end)
        Description copied from interface: IDateService
        Calculate the percentage of days passed between the start and end date.
        Specified by:
        getPercentageBetweenDates in interface IDateService
        Parameters:
        start - date
        end - date
        Returns:
        percentage of days passed in [0,1]
      • toDaysCiel

        public int toDaysCiel​(long milliseconds)
        Calculate the duration of milliseconds to ingame days and round up to the next full day.
        Parameters:
        milliseconds - real world milliseconds
        Returns:
        in game days.