Skip to content

Commit

Permalink
KNL-1554 Refactor of time service to aid deprecation (sakaiproject#4895)
Browse files Browse the repository at this point in the history
* KNL-1554 Refactor of time service to aid deprecation

This splits out a new API called UserTimeService which is just responsible for getting the user’s timezone at the moment. This allows the main TimeService to be deprecated and any place that uses TimeService to just get the user’s timezone can switch to using UserTimeService.

This also makes the current TimeService more testable as it doesn’t actually need the whole kernel to be running, just mock instances of 2 helpers that can be easily mocked with Mockito (or similar).

This also makes the classes more focused (Single Responsibility Principal).

* Fix space

* Code formatting cleanup (brackets).
  • Loading branch information
buckett authored and ern committed Oct 26, 2017
1 parent 012a3cd commit d3a3150
Show file tree
Hide file tree
Showing 11 changed files with 524 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
* <p>
* TimeService ...
* </p>
* @deprecated Please use {@link UserTimeService} or the new {@link java.time} package.
*/
public interface TimeService
public interface TimeService extends UserTimeService
{
/** The type string for this "application": should not change over time as it may be stored in various parts of persistent entities. */
static final String APPLICATION_ID = "sakai:time";
Expand Down Expand Up @@ -218,19 +219,6 @@ public interface TimeService
*/
TimeRange newTimeRange(Time start, Time end);

/**
* Access the users prefered local TimeZone.
*
* @return The user's local TimeZone.
*/
TimeZone getLocalTimeZone();

/**
* Clear local time zone for specified user
*
* @return true if successful
*/
boolean clearLocalTimeZone(String userId);

/**
* Get a Calendar, set to this zone and these values.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.sakaiproject.time.api;

import java.util.TimeZone;

/**
* This is an extraction out the user timezone specific parts of the TimeService. Refactorings can then be
* done to bind to this service when the rest of TimeService isn't needed.
*
* @see TimeService
*/
public interface UserTimeService {

/**
* Access the users preferred local TimeZone.
*
* @return The user's local TimeZone.
*/
TimeZone getLocalTimeZone();

/**
* Clear local time zone for specified user. Should be called when locale or timezone for user is changed.
*
* @return true if successful
*/
boolean clearLocalTimeZone(String userId);
}
Loading

0 comments on commit d3a3150

Please sign in to comment.