summaryrefslogtreecommitdiffstats
path: root/src/com/gitblit/wicket/GitBlitWebSession.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-04-04 09:10:51 -0400
committerJames Moger <james.moger@gitblit.com>2011-04-04 09:10:51 -0400
commit5fe7df81eb38dc66f2cfc4bf1973863a19f55cf2 (patch)
tree3f1b1b3f953aa8a5ed60e149043598fbdaf4d42f /src/com/gitblit/wicket/GitBlitWebSession.java
downloadgitblit-5fe7df81eb38dc66f2cfc4bf1973863a19f55cf2.tar.gz
gitblit-5fe7df81eb38dc66f2cfc4bf1973863a19f55cf2.zip
Initial import of Git:Blit.
Change-Id: Ifce000c85c8947c3a768e782c841e41a8953d314
Diffstat (limited to 'src/com/gitblit/wicket/GitBlitWebSession.java')
-rw-r--r--src/com/gitblit/wicket/GitBlitWebSession.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/com/gitblit/wicket/GitBlitWebSession.java b/src/com/gitblit/wicket/GitBlitWebSession.java
new file mode 100644
index 00000000..1eccb702
--- /dev/null
+++ b/src/com/gitblit/wicket/GitBlitWebSession.java
@@ -0,0 +1,74 @@
+package com.gitblit.wicket;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.apache.wicket.Request;
+import org.apache.wicket.Session;
+import org.apache.wicket.protocol.http.WebSession;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+
+import com.gitblit.StoredSettings;
+
+
+public final class GitBlitWebSession extends WebSession {
+
+ private static final long serialVersionUID = 1L;
+
+ protected TimeZone timezone = null;
+
+ public GitBlitWebSession(Request request) {
+ super(request);
+ }
+
+ public void invalidate() {
+ super.invalidate();
+ }
+
+ public TimeZone getTimezone() {
+ if (timezone == null) {
+ timezone = ((WebClientInfo) getClientInfo()).getProperties().getTimeZone();
+ }
+ // use server timezone if we can't determine the client timezone
+ if (timezone == null) {
+ timezone = TimeZone.getDefault();
+ }
+ return timezone;
+ }
+
+ public String formatTime(Date date) {
+ DateFormat df = new SimpleDateFormat(StoredSettings.getString("timestampFormat", "h:mm a"));
+ df.setTimeZone(getTimezone());
+ return df.format(date);
+ }
+
+ public String formatDate(Date date) {
+ DateFormat df = new SimpleDateFormat(StoredSettings.getString("datestampShortFormat", "MM/dd/yy"));
+ df.setTimeZone(getTimezone());
+ return df.format(date);
+ }
+
+ public String formatDateLong(Date date) {
+ DateFormat df = new SimpleDateFormat(StoredSettings.getString("datestampLongFormat", "EEEE, MMMM d, yyyy"));
+ df.setTimeZone(getTimezone());
+ return df.format(date);
+ }
+
+ public String formatDateTime(Date date) {
+ DateFormat df = new SimpleDateFormat(StoredSettings.getString("datetimestampShortFormat", "MM/dd/yy h:mm a"));
+ df.setTimeZone(getTimezone());
+ return df.format(date);
+ }
+
+ public String formatDateTimeLong(Date date) {
+ DateFormat df = new SimpleDateFormat(StoredSettings.getString("datetimestampLongFormat", "EEEE, MMMM d, yyyy h:mm a"));
+ df.setTimeZone(getTimezone());
+ return df.format(date);
+ }
+
+ public static GitBlitWebSession get() {
+ return (GitBlitWebSession) Session.get();
+ }
+} \ No newline at end of file