Class DateService
- java.lang.Object
-
- ch.sahits.game.openpatrician.clientserverinterface.service.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
-
-
Constructor Summary
Constructors Constructor Description DateService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetAge(java.time.LocalDateTime birthDate)Calculate the age.doublegetPercentageBetweenDates(java.time.LocalDateTime start, java.time.LocalDateTime end)Calculate the percentage of days passed between the start and end date.booleanisPast(java.time.LocalDateTime date)Check if a date lies in the past.booleanisSameDay(java.time.LocalDateTime date1, java.time.LocalDateTime date2)Check if two dates represent the same daybooleanisToday(java.time.LocalDateTime date)Check if the date is today.inttoDaysCiel(long milliseconds)Calculate the duration of milliseconds to ingame days and round up to the next full day.
-
-
-
Field Detail
-
date
@Autowired private Date date
-
-
Method Detail
-
isSameDay
public boolean isSameDay(java.time.LocalDateTime date1, java.time.LocalDateTime date2)Description copied from interface:IDateServiceCheck if two dates represent the same day- Specified by:
isSameDayin interfaceIDateService- Parameters:
date1- first date to compairdate2- 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:IDateServiceCheck if the date is today.- Specified by:
isTodayin interfaceIDateService- Parameters:
date- to chack against the current date- Returns:
- true if
dateis on the same day as current date
-
isPast
public boolean isPast(java.time.LocalDateTime date)
Description copied from interface:IDateServiceCheck if a date lies in the past.- Specified by:
isPastin interfaceIDateService- 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:IDateServiceCalculate the age.- Specified by:
getAgein interfaceIDateService- 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:IDateServiceCalculate the percentage of days passed between the start and end date.- Specified by:
getPercentageBetweenDatesin interfaceIDateService- Parameters:
start- dateend- 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.
-
-