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

Merge branch 'f-info-timezone' into 'dev'

EHN: add timezone info to Info Resource

See merge request caosdb/caosdb-server!32
parents 0a9b0a5c 683a81d4
Branches
Tags
No related merge requests found
......@@ -111,4 +111,17 @@ public class UTCTimeZoneShift extends TimeZone {
public String getID() {
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 @@
*/
package caosdb.server.resource;
import caosdb.datetime.UTCTimeZoneShift;
import caosdb.server.database.backend.implementation.MySQL.ConnectionException;
import caosdb.server.database.misc.TransactionBenchmark;
import caosdb.server.utils.FlagInfo;
import caosdb.server.utils.Info;
import java.util.TimeZone;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
......@@ -43,6 +45,7 @@ public class InfoResource extends AbstractCaosDBServerResource {
protected Representation httpGetInChildClass() throws Exception {
final Document doc = new Document();
final Element root = generateRootElement();
root.addContent(getTimeZone());
root.addContent(Info.toElement());
root.addContent(FlagInfo.toElement());
root.addContent(TransactionBenchmark.getRootInstance().toElememt());
......@@ -50,6 +53,14 @@ public class InfoResource extends AbstractCaosDBServerResource {
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. */
@Override
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