Date, Time, Timestamp, and TimestampOffset

You can represent database attribute types in JSON as string values.  maps the various attributes to the following internal types:
lac52
You can represent database attribute types in JSON as string values. 
Layer7 Live API Creator
maps the various attributes to the following internal types:
  • SimpleDate
    class
  • SimpleTime
    class
  • SimpleTimestamp
     class
  • SimpleTimestampOffset
     class
You can reference these internal types in the code editor for rules, resources, events, and functions.
In this article:
Date Data Type
You can return year, month, and day using the 
SimpleDate
 class. The following code snippet shows examples for the
date
data type:
var SimpleDate = Java.type("com.kahuna.util.SimpleDate"); var mydate = new SimpleDate(2017,12,31); //year, month, day // mydate = SimpleDate.valueOf("2017-12-31"); // var year = mydate.getYear(); // var month = mydate.getMonth(); // var day = mydate.getDay(); // mydate = SimpleDate.fromJavaUtilDate(new Date());
Time Data Type
You can return hours, minutes, seconds, and picos using the 
SimpleTime
 class. The following code snippet shows examples for the
time
data type:
var SimpleTime = Java.type("com.kahuna.util.SimpleTime"); var st = new SimpleTime(12,59,59,123455678); //hours (1-24), minutes (0-59), seconds (0-59), picos // st = "12:59:59"; // st = SimpleTime.valueOf("12:59:59:12345678"); // st = SimpleTime.fromJavaUtilDate(new Date()); // var hour = st.getHours(); // var minute = st.getMinutes(); // var seconds = st.getSeconds(); // var picos = st.getPicos();
Timestamp Data Type
You can return hours, minutes, seconds, picos, and offset using the 
SimpleTimestamp
 class. The following code snippet shows examples for the
timestamp
data type:
var SimpleTimestamp = Java.type("com.kahuna.util.SimpleTimestamp"); var sts = new SimpleTimestamp(2017,12,31,12,59,59,123456789); // sts = "2017-12-31T59:59:12345678"; // sts = SimpleTimestamp fromJavaUtilDate(new Date()); // sts = SimpleTimestamp.valueOf("2017-12-31T59:59:12345678"); // var year = sts.getYear(); // var month = sts.getMonth(); // var day = sts.getDay(); // var hour = sts.getHours(); // var minute = sts.getMinutes(); // var seconds = sts.getSeconds(); // var picos = sts.getPicos();
TimestampOffset Data Type
You can support databases that include an offset from Greenwich Mean Time (GMT) using the 
SimpleTimestampOffset
 class. The syntax includes a positive/negative offset from GMT plus hours and seconds. The following code snippet shows examples for the
TimestampOffset
data type:
//valid format is [-]yyyy-mm-dd[ -tT]hh[-.:]mm[-.:]ss[-.:] [positive offset] [hours][minutes] var SimpleTimestampOffset = Java.type("com.kahuna.util.SimpleTimestampOffset"); var stso = new SimpleTimestampOffset(2017,12,31,12,59,59,false,5,0); //New York // stso = "2017-12-31T59:59:59.123456789123-0500"; // stso = "2017-12-31T59:59:59.123456789123-0500"; // stso = SimpleTimestampOffset.fromJavaUtilDate(new Date()); // stso = stso.asSimpleTimestampAdjusted(); // stso = SimpleTimestampOffset.valueOf("2017-12-31T59:59:59.123456789123-0500"); // var year = stso.getYear(); // var month = stso.getMonth(); // var day = stso.getDay(); // var hour = stso.getHours(); // var minute = stso.getMinutes(); // var seconds = stso.getSeconds(); // var picos = stso.getPicos(); // var isOffsetPositive = stso.isOffsetPositive(); // var nanos = stso.getNanos(); // var offset = stso.getOffset(); // returns SimpleOffset // var offsetHours = offset.getOffsetHours();