1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.asterisk.util;
18
19 import java.util.Date;
20
21 /***
22 * Utility class to obtain the current date and allows to override with a fixed value for testing.
23 *
24 * @author srt
25 * @version $Id: DateUtil.java,v 1.1 2005/03/11 15:31:47 srt Exp $
26 */
27 public class DateUtil
28 {
29 private static Date currentDate;
30
31 private DateUtil()
32 {
33 }
34
35 /***
36 * If set to a non null value uses the date given as current date on calls to getDate(). Set to
37 * null to restore the normal behavior.
38 *
39 * @param currentDate the date to return on calls to getDate() or <code>null</code> to return
40 * the real current date.
41 */
42 public static void overrideCurrentDate(Date currentDate)
43 {
44 DateUtil.currentDate = currentDate;
45 }
46
47 /***
48 * Returns the real current date or the date set with overrideCurrentDate().
49 *
50 * @return the real current date or the date set with overrideCurrentDate().
51 */
52 public static Date getDate()
53 {
54 if (currentDate != null)
55 {
56 return currentDate;
57 }
58 else
59 {
60 return new Date();
61 }
62 }
63 }