Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/bug-1108546 into 
lp:zorba.

Commit message:
Added millis-to-dateTime().

Requested reviews:
  Paul J. Lucas (paul-lucas)
Related bugs:
  Bug #1108546 in Zorba: "Add function to datetime module to convert 
milliseconds since epoch to dateTime"
  https://bugs.launchpad.net/zorba/+bug/1108546

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/bug-1108546/+merge/145396

Added millis-to-dateTime().
-- 
https://code.launchpad.net/~paul-lucas/zorba/bug-1108546/+merge/145396
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2013-01-22 11:07:53 +0000
+++ ChangeLog	2013-01-29 15:18:26 +0000
@@ -6,6 +6,7 @@
   * Typeswitch expression extended to allow union of types in each case clause,
     as specified by XQuery v3.0
   * Extended sequence types to include unions, as specified by XQuery v3.0
+  * Added millis-to-dateTime() function in datetime module.
 
 Optimizations:
 

=== modified file 'modules/com/zorba-xquery/www/modules/datetime.xq'
--- modules/com/zorba-xquery/www/modules/datetime.xq	2013-01-08 01:45:26 +0000
+++ modules/com/zorba-xquery/www/modules/datetime.xq	2013-01-29 15:18:26 +0000
@@ -249,6 +249,17 @@
 ) as xs:time external;
 
 (:~
+ : Converts the given number of milliseconds since epoch into its corresponding
+ : xs:dateTime.
+ :
+ : @param $millis The number of milliseconds since epoch.
+ : @return Returns an xs:dateTime.
+ : @example test/rbkt/Queries/zorba/datetime/datetime-millis-to-dateTime-1.xq
+ :)
+declare function datetime:millis-to-dateTime( $millis as xs:long )
+  as xs:dateTime external;
+
+(:~
  : Gets the the number of milliseconds since epoch.
  :
  : @return the said number of milliseconds.

=== modified file 'src/functions/pregenerated/func_datetime.cpp'
--- src/functions/pregenerated/func_datetime.cpp	2013-01-04 16:08:03 +0000
+++ src/functions/pregenerated/func_datetime.cpp	2013-01-29 15:18:26 +0000
@@ -61,6 +61,16 @@
   return new CurrentTime(sctx, loc, argv);
 }
 
+PlanIter_t fn_zorba_dateTime_millis_to_dateTime::codegen(
+  CompilerCB*,
+  static_context* sctx,
+  const QueryLoc& loc,
+  std::vector<PlanIter_t>& argv,
+  expr& ann) const
+{
+  return new MillisToDateTime(sctx, loc, argv);
+}
+
 PlanIter_t fn_zorba_dateTime_parse_date::codegen(
   CompilerCB*,
   static_context* sctx,
@@ -149,6 +159,18 @@
 
 
       {
+    DECL_WITH_KIND(sctx, fn_zorba_dateTime_millis_to_dateTime,
+        (createQName("http://www.zorba-xquery.com/modules/datetime","","millis-to-dateTime";), 
+        GENV_TYPESYSTEM.LONG_TYPE_ONE, 
+        GENV_TYPESYSTEM.DATETIME_TYPE_ONE),
+        FunctionConsts::FN_ZORBA_DATETIME_MILLIS_TO_DATETIME_1);
+
+  }
+
+
+
+
+      {
     DECL_WITH_KIND(sctx, fn_zorba_dateTime_parse_date,
         (createQName("http://www.zorba-xquery.com/modules/datetime","","parse-date";), 
         GENV_TYPESYSTEM.STRING_TYPE_ONE, 

=== modified file 'src/functions/pregenerated/func_datetime.h'
--- src/functions/pregenerated/func_datetime.h	2012-12-21 21:19:25 +0000
+++ src/functions/pregenerated/func_datetime.h	2013-01-29 15:18:26 +0000
@@ -83,6 +83,21 @@
 };
 
 
+//fn-zorba-dateTime:millis-to-dateTime
+class fn_zorba_dateTime_millis_to_dateTime : public function
+{
+public:
+  fn_zorba_dateTime_millis_to_dateTime(const signature& sig, FunctionConsts::FunctionKind kind)
+    : 
+    function(sig, kind)
+  {
+
+  }
+
+  CODEGEN_DECL();
+};
+
+
 //fn-zorba-dateTime:parse-date
 class fn_zorba_dateTime_parse_date : public function
 {

=== modified file 'src/functions/pregenerated/function_enum.h'
--- src/functions/pregenerated/function_enum.h	2013-01-11 17:37:08 +0000
+++ src/functions/pregenerated/function_enum.h	2013-01-29 15:18:26 +0000
@@ -146,6 +146,7 @@
   FN_ZORBA_DATETIME_CURRENT_DATE_0,
   FN_ZORBA_DATETIME_CURRENT_DATETIME_0,
   FN_ZORBA_DATETIME_CURRENT_TIME_0,
+  FN_ZORBA_DATETIME_MILLIS_TO_DATETIME_1,
   FN_ZORBA_DATETIME_PARSE_DATE_2,
   FN_ZORBA_DATETIME_PARSE_DATE_3,
   FN_ZORBA_DATETIME_PARSE_DATETIME_2,

=== modified file 'src/runtime/datetime/datetime_impl.cpp'
--- src/runtime/datetime/datetime_impl.cpp	2013-01-08 00:31:47 +0000
+++ src/runtime/datetime/datetime_impl.cpp	2013-01-29 15:18:26 +0000
@@ -222,6 +222,34 @@
   STACK_END( state );
 }
 
+bool MillisToDateTime::nextImpl( store::Item_t& result,
+                                 PlanState &plan_state ) const {
+  store::Item_t item;
+  xs_long millis;
+  time::ztm tm;
+
+  PlanIteratorState *state;
+  DEFAULT_STACK_INIT( PlanIteratorState, state, plan_state );
+
+  consumeNext( item, theChildren[0], plan_state );
+  millis = item->getLongValue();
+
+  time::get_gmtime( &tm, static_cast<time_t>( millis / 1000 ) );
+  GENV_ITEMFACTORY->createDateTime(
+    result,
+    static_cast<short>( tm.tm_year + TM_YEAR_BASE ),
+    static_cast<short>( tm.tm_mon + 1 ),
+    static_cast<short>( tm.tm_mday ),
+    static_cast<short>( tm.tm_hour ),
+    static_cast<short>( tm.tm_min ),
+    tm.tm_sec + (millis % 1000) / 1000.0,
+    static_cast<short>( tm.ZTM_GMTOFF / 3600 )
+  );
+
+  STACK_PUSH( true, state );
+  STACK_END( state );
+}
+
 bool ParseDate::nextImpl( store::Item_t& result, PlanState &plan_state ) const {
   store::Item_t item;
   zstring buf, fmt;

=== modified file 'src/runtime/datetime/pregenerated/datetime.cpp'
--- src/runtime/datetime/pregenerated/datetime.cpp	2012-12-23 02:12:16 +0000
+++ src/runtime/datetime/pregenerated/datetime.cpp	2013-01-29 15:18:26 +0000
@@ -116,6 +116,34 @@
 // </CurrentTime>
 
 
+// <MillisToDateTime>
+SERIALIZABLE_CLASS_VERSIONS(MillisToDateTime)
+
+void MillisToDateTime::serialize(::zorba::serialization::Archiver& ar)
+{
+  serialize_baseclass(ar,
+  (NaryBaseIterator<MillisToDateTime, PlanIteratorState>*)this);
+}
+
+
+void MillisToDateTime::accept(PlanIterVisitor& v) const
+{
+  v.beginVisit(*this);
+
+  std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
+  std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
+  for ( ; lIter != lEnd; ++lIter ){
+    (*lIter)->accept(v);
+  }
+
+  v.endVisit(*this);
+}
+
+MillisToDateTime::~MillisToDateTime() {}
+
+// </MillisToDateTime>
+
+
 // <ParseDate>
 SERIALIZABLE_CLASS_VERSIONS(ParseDate)
 

=== modified file 'src/runtime/datetime/pregenerated/datetime.h'
--- src/runtime/datetime/pregenerated/datetime.h	2012-12-23 02:12:16 +0000
+++ src/runtime/datetime/pregenerated/datetime.h	2013-01-29 15:18:26 +0000
@@ -132,6 +132,38 @@
 
 /**
  * 
+ *    function for converting seconds since epoch to an xs:dateTime
+ *  
+ * Author: Zorba Team
+ */
+class MillisToDateTime : public NaryBaseIterator<MillisToDateTime, PlanIteratorState>
+{ 
+public:
+  SERIALIZABLE_CLASS(MillisToDateTime);
+
+  SERIALIZABLE_CLASS_CONSTRUCTOR2T(MillisToDateTime,
+    NaryBaseIterator<MillisToDateTime, PlanIteratorState>);
+
+  void serialize( ::zorba::serialization::Archiver& ar);
+
+  MillisToDateTime(
+    static_context* sctx,
+    const QueryLoc& loc,
+    std::vector<PlanIter_t>& children)
+    : 
+    NaryBaseIterator<MillisToDateTime, PlanIteratorState>(sctx, loc, children)
+  {}
+
+  virtual ~MillisToDateTime();
+
+  void accept(PlanIterVisitor& v) const;
+
+  bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
+};
+
+
+/**
+ * 
  *    function for parsing strings into a date
  *  
  * Author: Zorba Team

=== modified file 'src/runtime/pregenerated/iterator_enum.h'
--- src/runtime/pregenerated/iterator_enum.h	2013-01-11 17:37:08 +0000
+++ src/runtime/pregenerated/iterator_enum.h	2013-01-29 15:18:26 +0000
@@ -75,6 +75,7 @@
   TYPE_CurrentDate,
   TYPE_CurrentDateTime,
   TYPE_CurrentTime,
+  TYPE_MillisToDateTime,
   TYPE_ParseDate,
   TYPE_ParseDateTime,
   TYPE_ParseTime,

=== modified file 'src/runtime/spec/datetime/datetime.xml'
--- src/runtime/spec/datetime/datetime.xml	2013-01-04 16:08:03 +0000
+++ src/runtime/spec/datetime/datetime.xml	2013-01-29 15:18:26 +0000
@@ -44,6 +44,18 @@
   </zorba:function>
 </zorba:iterator>
 
+<zorba:iterator name="MillisToDateTime">
+  <zorba:description author="Zorba Team">
+    function for converting seconds since epoch to an xs:dateTime
+  </zorba:description>
+  <zorba:function>
+    <zorba:signature localname="millis-to-dateTime" prefix="fn-zorba-dateTime">
+      <zorba:param>xs:long</zorba:param>    <!-- millis -->
+      <zorba:output>xs:dateTime</zorba:output>
+    </zorba:signature>
+  </zorba:function>
+</zorba:iterator>
+
 <zorba:iterator name="ParseDate">
   <zorba:description author="Zorba Team">
     function for parsing strings into a date

=== modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h'
--- src/runtime/visitors/pregenerated/planiter_visitor.h	2013-01-11 17:37:08 +0000
+++ src/runtime/visitors/pregenerated/planiter_visitor.h	2013-01-29 15:18:26 +0000
@@ -140,6 +140,8 @@
 
     class CurrentTime;
 
+    class MillisToDateTime;
+
     class ParseDate;
 
     class ParseDateTime;
@@ -933,6 +935,9 @@
     virtual void beginVisit ( const CurrentTime& ) = 0;
     virtual void endVisit   ( const CurrentTime& ) = 0;
 
+    virtual void beginVisit ( const MillisToDateTime& ) = 0;
+    virtual void endVisit   ( const MillisToDateTime& ) = 0;
+
     virtual void beginVisit ( const ParseDate& ) = 0;
     virtual void endVisit   ( const ParseDate& ) = 0;
 

=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp'
--- src/runtime/visitors/pregenerated/printer_visitor.cpp	2013-01-11 17:37:08 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.cpp	2013-01-29 15:18:26 +0000
@@ -746,6 +746,20 @@
 // </CurrentTime>
 
 
+// <MillisToDateTime>
+void PrinterVisitor::beginVisit ( const MillisToDateTime& a) {
+  thePrinter.startBeginVisit("MillisToDateTime", ++theId);
+  printCommons( &a, theId );
+  thePrinter.endBeginVisit( theId );
+}
+
+void PrinterVisitor::endVisit ( const MillisToDateTime& ) {
+  thePrinter.startEndVisit();
+  thePrinter.endEndVisit();
+}
+// </MillisToDateTime>
+
+
 // <ParseDate>
 void PrinterVisitor::beginVisit ( const ParseDate& a) {
   thePrinter.startBeginVisit("ParseDate", ++theId);

=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.h'
--- src/runtime/visitors/pregenerated/printer_visitor.h	2013-01-11 17:37:08 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.h	2013-01-29 15:18:26 +0000
@@ -212,6 +212,9 @@
     void beginVisit( const CurrentTime& );
     void endVisit  ( const CurrentTime& );
 
+    void beginVisit( const MillisToDateTime& );
+    void endVisit  ( const MillisToDateTime& );
+
     void beginVisit( const ParseDate& );
     void endVisit  ( const ParseDate& );
 

=== added file 'test/rbkt/ExpQueryResults/zorba/datetime/datetime-millis-to-dateTime-1.xml.res'
--- test/rbkt/ExpQueryResults/zorba/datetime/datetime-millis-to-dateTime-1.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/datetime/datetime-millis-to-dateTime-1.xml.res	2013-01-29 15:18:26 +0000
@@ -0,0 +1,1 @@
+2013-01-29T05:56:53.001Z

=== added file 'test/rbkt/Queries/zorba/datetime/datetime-millis-to-dateTime-1.xq'
--- test/rbkt/Queries/zorba/datetime/datetime-millis-to-dateTime-1.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/datetime/datetime-millis-to-dateTime-1.xq	2013-01-29 15:18:26 +0000
@@ -0,0 +1,3 @@
+import module namespace dt = "http://www.zorba-xquery.com/modules/datetime";;
+
+dt:millis-to-dateTime( xs:long( 1359439013001 ) )

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to