summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/util
diff options
context:
space:
mode:
authorJonathan Bauer2015-09-10 17:45:18 +0200
committerJonathan Bauer2015-09-10 17:45:18 +0200
commit8a775f1d03ceb36383ef620c8116199cf6e2da28 (patch)
tree0561fc2e8f9187509fa5f5474bae47641bda4301 /dozentenmodul/src/main/java/org/openslx/dozmod/util
parent[client] workaround for wrongly assigned error message when uploading new ima... (diff)
downloadtutor-module-8a775f1d03ceb36383ef620c8116199cf6e2da28.tar.gz
tutor-module-8a775f1d03ceb36383ef620c8116199cf6e2da28.tar.xz
tutor-module-8a775f1d03ceb36383ef620c8116199cf6e2da28.zip
[client] added "Expiring" column to versionTable and introduced FormatHelper.daysTil(<long_timestamp_in_millis>)
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/util')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java38
1 files changed, 37 insertions, 1 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java
index 26c7071a..5594be6a 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java
@@ -1,7 +1,14 @@
package org.openslx.dozmod.util;
+import java.util.Calendar;
+
+import org.joda.time.DateTime;
+import org.joda.time.Days;
+import org.joda.time.Period;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.PeriodFormat;
+import org.joda.time.format.PeriodFormatter;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.UserInfo;
@@ -112,5 +119,34 @@ public class FormatHelper {
return ret + String.format("%02d:%02d", seconds / 3600, (seconds % 3600) / 60);
}
}
-
+ /**
+ * Returns the number of days left til the given end timestamp
+ *
+ * @param timestamp to calculate the days until
+ * @return user-ready String containing the amount of days left if <14 days and > 24h,
+ * the number of hours left if <24. If end is already passed, then just
+ * the same as longDate
+ */
+ public static String daysTil(final long timestamp) {
+ Period period = new Period(DateTime.now().getMillis(), timestamp * 1000);
+ if (period.getYears() > 0 || period.getMonths() > 0 || period.getWeeks() > 2) {
+ return longDate(timestamp);
+ } else {
+ // under 2 weeks, get the days and add the week if any
+ int daysLeft = period.getDays();
+ if (period.getWeeks() == 1)
+ daysLeft += 7;
+ if (daysLeft <= 14 && daysLeft >= 1) {
+ return new String(daysLeft + " Tag(e)");
+ } else if (daysLeft == 0) {
+ int hoursLeft = period.getHours();
+ if (hoursLeft != 0) {
+ return new String(hoursLeft + " Stunde(n)");
+ } else {
+ return new String(period.getMinutes() + " Minute(n)");
+ }
+ }
+ }
+ return "-"; // Error
+ }
}