Veyder-time
Veyder-time is a simple and efficient time and date framework for Java. It simplifies many operations with times and dates, and offers a more natural representation for such objects.
- It has a simple, intuitive and well-documented API.
- No time zones. No locales. Only the normal calendar system. No eras.
- Dates can be represented as dates alone, without unneccessary time information.
- Formatting of times and dates is very easy - no cryptic format description strings.
- The implementation is very efficient, and the memory usage is minimal.
- The framework is well-tested, with extensive unit tests.
- ... and much more.
Veyder-time is very simple to use. The main objects are:
Time
– a complete timestamp with date and time of day
DayDate
– a simple date without time of day
TimeOfDay
– a time of day
Here are some examples:
Creating
Time now = Time.factory.now();
Time time = Time.factory.parse("2011-08-01 12:49:21.123");
DayDate date = DayDate.factory.parse("2011", "08", "01");
TimeOfDay time = TimeOfDay.factory.parse(12, 49, 21);
Comparing
if (time.isBefore("09", "15")) { /* something appropriate before 9:15 */ }
if (time.isLaterDayThan(lastTime)) { /* a once-a-day task */ }
if (time1.isSameMinuteAs(time2)) { /* gather events of same minute */ }
Calculating
DayOfWeek dow = time.getDayOfWeek();
Time newTime = time.plusMinutes(123);
Time newTime = time.plusSeconds(-42);
DayDate newDate = date.plusYears(401);
int diff = TimeUtils.differenceInDays(date1, date2);
Formatting
time.iso().formatDateAndTime(); // 2011-08-01 12:49:21
time.eur().formatDateAndTime(); // 01.08.2011 12:49:21
time.us().formatDateAndTime(); // 08/01/2011 12:49:21
time.iso().formatDateAndLongTime(); // 2011-08-01 12:49:21.123
time.iso().formatCompactDate(); // 20110801
time.iso().formatShortTime(); // 12:49
time.eur().formatCompactShortDateAndTime(); // 010811 12:49:21
time.us().formatShortDateAndShortTime(); // 08/01/11 12:49
Persisting
String data = time.serialize();
Time time = Time.factory.deserialize(data);
Converting
java.util.Date date = time.toJavaUtilDate(timeZone);
TimeOfDay time = Time.factory.fromJavaUtilDate(date).getTimeOfDay();