Skip to content
Snippets Groups Projects
Verified Commit 683a81d4 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

EHN: add timezone info to Info Resource

parent 0a9b0a5c
No related branches found
No related tags found
No related merge requests found
...@@ -111,4 +111,17 @@ public class UTCTimeZoneShift extends TimeZone { ...@@ -111,4 +111,17 @@ public class UTCTimeZoneShift extends TimeZone {
public String getID() { public String getID() {
return str; return str;
} }
/**
* Generate an ISO 8601 time zone offset string (e.g. +0200) from the given raw offset in
* milliseconds.
*
* @param rawOffset - offset in ms.
* @return ISO 8601 time zone offset.
*/
public static String getISO8601Offset(int rawOffset) {
int h = Integer.divideUnsigned(rawOffset, 1000 * 60 * 60);
int m = Integer.remainderUnsigned(rawOffset, 1000 * 60 * 60);
return generateString(Integer.signum(h), h, m);
}
} }
...@@ -22,10 +22,12 @@ ...@@ -22,10 +22,12 @@
*/ */
package caosdb.server.resource; package caosdb.server.resource;
import caosdb.datetime.UTCTimeZoneShift;
import caosdb.server.database.backend.implementation.MySQL.ConnectionException; import caosdb.server.database.backend.implementation.MySQL.ConnectionException;
import caosdb.server.database.misc.TransactionBenchmark; import caosdb.server.database.misc.TransactionBenchmark;
import caosdb.server.utils.FlagInfo; import caosdb.server.utils.FlagInfo;
import caosdb.server.utils.Info; import caosdb.server.utils.Info;
import java.util.TimeZone;
import org.jdom2.Document; import org.jdom2.Document;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.JDOMException; import org.jdom2.JDOMException;
...@@ -43,6 +45,7 @@ public class InfoResource extends AbstractCaosDBServerResource { ...@@ -43,6 +45,7 @@ public class InfoResource extends AbstractCaosDBServerResource {
protected Representation httpGetInChildClass() throws Exception { protected Representation httpGetInChildClass() throws Exception {
final Document doc = new Document(); final Document doc = new Document();
final Element root = generateRootElement(); final Element root = generateRootElement();
root.addContent(getTimeZone());
root.addContent(Info.toElement()); root.addContent(Info.toElement());
root.addContent(FlagInfo.toElement()); root.addContent(FlagInfo.toElement());
root.addContent(TransactionBenchmark.getRootInstance().toElememt()); root.addContent(TransactionBenchmark.getRootInstance().toElememt());
...@@ -50,6 +53,14 @@ public class InfoResource extends AbstractCaosDBServerResource { ...@@ -50,6 +53,14 @@ public class InfoResource extends AbstractCaosDBServerResource {
return ok(doc); return ok(doc);
} }
public Element getTimeZone() {
TimeZone d = TimeZone.getDefault();
return new Element("TimeZone")
.setAttribute("offset", UTCTimeZoneShift.getISO8601Offset(d.getRawOffset()))
.setAttribute("id", d.getID())
.addContent(d.getDisplayName());
}
/** There is no POST request specified for the /Info resource. */ /** There is no POST request specified for the /Info resource. */
@Override @Override
protected Representation httpPostInChildClass(final Representation entity) protected Representation httpPostInChildClass(final Representation entity)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment