I am using a Java backend to store different events. Up to now Date is used to store date and time specific information. It would be nice to allow "more natural" time definitions like "afternoon", "morning" or "soon".
Are there any best practices to handle these flexible/not well specified but often used time specifiers? Are there some libraries to transform them into Date objects (and vice versa)?
How about doing that by hand. Just create a wrapper class and make an enum with values AfterNoon, Morning, ... And provide a constructor that takes a Date object and code the logic as you want.
Class DateWrapper {
private Date date;
private DayTime dayTime;
public DateWrapper (Date date){
...
}
public enum DayTime {
Morning, AfterNoon, ...;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With