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 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 dayboolean
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.
-
-
-
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:IDateService
Check if two dates represent the same day- Specified by:
isSameDay
in 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:IDateService
Check if the date is today.- Specified by:
isToday
in interfaceIDateService
- 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 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:IDateService
Calculate the age.- Specified by:
getAge
in 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:IDateService
Calculate the percentage of days passed between the start and end date.- Specified by:
getPercentageBetweenDates
in 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.
-
-