I need to store LocalTime in field TIME as a local (not UTC)
Project moved to GitHub
Brought to you by:
broneill,
scolebourne
Class PersistentLocalTimeAsTime writes to database time in UFC zone.
I'd like to a write LocalTime as a local time.
To achieve this I had to change "nullSafeGet" method from:
return new LocalTime(timestamp, DateTimeZone.UTC);
to
return new LocalTime(timestamp);
and "nullSafeSet" from:
Time time = new Time(lt.getHourOfDay(), lt.getMinuteOfHour(), lt.getSecondOfMinute());
to:
Calendar cal = Calendar.getInstance();
cal.set( Calendar.HOUR_OF_DAY, lt.getHourOfDay() );
cal.set( Calendar.MINUTE, lt.getMinuteOfHour() );
cal.set( Calendar.SECOND, lt.getSecondOfMinute() );
cal.set( Calendar.MILLISECOND, lt.getMillisOfSecond() );
Time time = new Time( cal.getTime().getTime() );
Have you looked at the User Type project - http://usertype.sourceforge.net/