-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'move-class-CurrentTimeUTC' into master
= Move class CurrentTimeUTC from fred to Freetalk The fred developers recently revamped the class, and then decided to deprecate the class in fred, hence Freetalk (and WoT) will have to contain it so it can be removed there. This branch only moves the class as it was before the modifications. I did not include these modifications yet because there is no unit test and I have no time to write one and also not to review the changes. A bugtracker issue has been filed to document that the modifications will have to be applied: https://bugs.freenetproject.org/view.php?id=7205
- Loading branch information
Showing
15 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* This code is part of Freenet. It is distributed under the GNU General | ||
* Public License, version 2 (or at your option any later version). See | ||
* http://www.gnu.org/ for further details of the GPL. */ | ||
package plugins.Freetalk.util; | ||
|
||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
import java.util.TimeZone; | ||
|
||
|
||
/** | ||
* A wrapper class around a GregorianCalendar which always returns the current time. | ||
* This is useful for working around the pitfall of class Calendar: It only returns the current time when you first use a get*() function, | ||
* in any get*() calls after the first call, the time value of the first call is returned. One would have to call Calendar.clear() before each | ||
* get to obtain the current time and this class takes care of that for you. | ||
* | ||
* Further, this class is synchronized so you do not need to worry about synchronization of a Calendar anymore. | ||
*/ | ||
public class CurrentTimeUTC { | ||
|
||
private static final GregorianCalendar mCalendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); | ||
|
||
public static Date get() { | ||
synchronized(mCalendar) { | ||
mCalendar.setTimeInMillis(System.currentTimeMillis()); | ||
return mCalendar.getTime(); | ||
} | ||
} | ||
|
||
/** | ||
* Get the current time in milliseconds. | ||
* | ||
* In the current implementation, this just returns System.currentTimeMilis(). You should however use CurrenTimeUTC.getInMillis() instead because | ||
* the JavaDoc of System.currentTimeMilis() does not explicitly state what time zone it returns. Therefore, by using this wrapper function, your code | ||
* clearly states that it uses UTC time. | ||
*/ | ||
public static long getInMillis() { | ||
return System.currentTimeMillis(); | ||
} | ||
|
||
public static int getYear() { | ||
synchronized(mCalendar) { | ||
mCalendar.setTimeInMillis(System.currentTimeMillis()); | ||
return mCalendar.get(Calendar.YEAR); | ||
} | ||
} | ||
|
||
public static int getMonth() { | ||
synchronized(mCalendar) { | ||
mCalendar.setTimeInMillis(System.currentTimeMillis()); | ||
return mCalendar.get(Calendar.MONTH); | ||
} | ||
} | ||
|
||
public static int getDayOfMonth() { | ||
synchronized(mCalendar) { | ||
mCalendar.setTimeInMillis(System.currentTimeMillis()); | ||
return mCalendar.get(Calendar.DAY_OF_MONTH); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters