source: trunk/src/org/expeditee/stats/Formatter.java@ 1442

Last change on this file since 1442 was 974, checked in by bln4, 9 years ago

Publicified one of the formatter strings so we can use it for comparing dates.
Attract and Repel Text can now be turned on and off via a static field

File size: 2.3 KB
Line 
1/**
2 * Formatter.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.stats;
20
21import java.sql.Time;
22import java.text.SimpleDateFormat;
23import java.util.Date;
24
25public class Formatter {
26
27 public static final String DATE_FORMAT = "ddMMMyyyy";
28
29 public static final String TIME_FORMAT = "[HH:mm]";
30
31 private static final String LONG_TIME_FORMAT = "[HH:mm.ss]";
32
33 private static final String TIME_WITH_MILLISECONDS = "mm:ss:SSS";
34
35 public static final String LONG_DATE_TIME_FORMAT = DATE_FORMAT
36 + LONG_TIME_FORMAT;
37
38 public static final String DATE_TIME_FORMAT = DATE_FORMAT + TIME_FORMAT;
39
40 private static String EasyDateFormat(String format, Date date) {
41 return (new SimpleDateFormat(format)).format(date);
42 }
43
44 private static String EasyDateFormat(String format) {
45 return EasyDateFormat(format, new Date());
46 }
47
48 public static String getTimePeriod(Time time) {
49 /*
50 * Truncate the millis
51 */
52 long total = time.getTime() / 1000;
53 long seconds = total % 60;
54 // Truncate the secs
55 total /= 60;
56 long minutes = total % 60;
57 // Truncate the minutes
58 long hours = total / 60;
59
60 return String.format("%1$02d:%2$02d:%3$02d", hours, minutes, seconds);
61 }
62
63 public static String getLongDateTime() {
64 return EasyDateFormat(LONG_DATE_TIME_FORMAT);
65 }
66
67 public static String getDateTime(Date dateTime) {
68 return EasyDateFormat(DATE_TIME_FORMAT, dateTime);
69 }
70
71 public static String getDateTime() {
72 return EasyDateFormat(DATE_TIME_FORMAT);
73 }
74
75 public static String getTimeWithMillis(Date elapsedTime) {
76 return EasyDateFormat(TIME_WITH_MILLISECONDS);
77 }
78
79 public static String getDate() {
80 return EasyDateFormat(DATE_FORMAT);
81 }
82
83}
Note: See TracBrowser for help on using the repository browser.