gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/asobj/Date.cpp


From: Benjamin Wolsey
Subject: [Gnash-commit] gnash ChangeLog server/asobj/Date.cpp
Date: Thu, 03 Apr 2008 14:34:14 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Benjamin Wolsey <bwy>   08/04/03 14:34:14

Modified files:
        .              : ChangeLog 
        server/asobj   : Date.cpp 

Log message:
                * server/asobj/Date.cpp: get current time from tu_timer, avoids
                  duplicating ifdefs. Clean ups of code and indentation.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6171&r2=1.6172
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Date.cpp?cvsroot=gnash&r1=1.58&r2=1.59

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6171
retrieving revision 1.6172
diff -u -b -r1.6171 -r1.6172
--- ChangeLog   3 Apr 2008 14:24:00 -0000       1.6171
+++ ChangeLog   3 Apr 2008 14:34:13 -0000       1.6172
@@ -1,3 +1,8 @@
+2008-04-03 Benjamin Wolsey <address@hidden>
+
+       * server/asobj/Date.cpp: get current time from tu_timer, avoids
+         duplicating ifdefs. Clean ups of code and indentation.
+
 2008-04-03 Udo Giacomozzi <address@hidden>
 
        * server/dlist.cpp: clear invalidated flag when skipping display() call;

Index: server/asobj/Date.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Date.cpp,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- server/asobj/Date.cpp       3 Apr 2008 10:41:28 -0000       1.58
+++ server/asobj/Date.cpp       3 Apr 2008 14:34:14 -0000       1.59
@@ -76,6 +76,7 @@
 #include "GnashException.h"
 #include "builtin_function.h"
 #include "Object.h" // for getObjectInterface
+#include "tu_timer.h"
 
 #include <ctime>
 #include <cmath>
@@ -363,33 +364,16 @@
   // The commercial player does different things according to which
   // args are NaNs or Infinities:
   // for now, we just use rogue_date_args' algorithm
-  {
     double foo;
     if ((foo = rogue_date_args(fn, 7)) != 0.0) {
       date->value = foo;
       return as_value(date);
     }
-  }
 
   // TODO: move this to date_as_object constructor
   if (fn.nargs < 1 || fn.arg(0).is_undefined()) {
     // Set from system clock
-#ifdef HAVE_GETTIMEOFDAY
-    struct timeval tv;
-    struct timezone tz;
-
-    gettimeofday(&tv,&tz);
-    date->value = static_cast<double>(tv.tv_sec) * 1000.0 +
-                  static_cast<double>(tv.tv_usec) / 1000.0;
-#elif defined(HAVE_FTIME)
-    struct timeb tb;
-
-    ftime (&tb);
-    date->value = (double)tb.time * 1000.0 + tb.millitm;
-#else
-    // Poo! Use old time() to get seconds only
-    date->value = time((time_t *) 0) * 1000.0;
-#endif
+        date->value = tu_timer::get_ticks();
     }
     else if (fn.nargs == 1) {
         // Set the value in milliseconds since 1970 UTC
@@ -537,7 +521,6 @@
 
 // Return the difference between UTC and localtime+DST for a given date/time
 // as the number of minutes east of GMT.
- 
 static int minutes_east_of_gmt(struct tm& /* tm*/)
 {
     return 0;
@@ -647,16 +630,20 @@
 /// \brief Date.setTime
 /// sets a Date in milliseconds after January 1, 1970 00:00 UTC.
 /// The return value is the same as the parameter.
-static as_value date_settime(const fn_call& fn) {
+static as_value
+date_settime(const fn_call& fn)
+{
   boost::intrusive_ptr<date_as_object> date = 
ensureType<date_as_object>(fn.this_ptr);
 
   if (fn.nargs < 1) {
       IF_VERBOSE_ASCODING_ERRORS(
     log_aserror(_("Date.setTime needs one argument"));
       )
-  } else
+    }
+    else {
     // returns a double
     date->value = fn.arg(0).to_number();
+    }
 
   if (fn.nargs > 1) {
       IF_VERBOSE_ASCODING_ERRORS(
@@ -781,8 +768,9 @@
 ///   should end up at March 1st of the same year.
 //
 // There is no setUTCYear() function.
-
-static as_value date_setyear(const fn_call& fn) {
+static as_value
+date_setyear(const fn_call& fn)
+{
   boost::intrusive_ptr<date_as_object> date = 
ensureType<date_as_object>(fn.this_ptr);
 
   // assert(fn.nargs == 1);
@@ -791,9 +779,11 @@
     log_aserror(_("Date.setYear needs one argument"));
       )
       date->value = NAN;
-  } else if (rogue_date_args(fn, 3) != 0.0) {
+    }
+    else if (rogue_date_args(fn, 3) != 0.0) {
       date->value = NAN;
-  } else {
+    }
+    else {
       GnashTime gt;
 
       dateToGnashTime(*date, gt, false);
@@ -802,10 +792,8 @@
       // full year spec, we must adjust it.
       if (gt.year >= 100) gt.year -= 1900;
 
-      if (fn.nargs >= 2)
-    gt.month = fn.arg(1).to_int();
-      if (fn.nargs >= 3)
-    gt.monthday = fn.arg(2).to_int();
+        if (fn.nargs >= 2) gt.month = fn.arg(1).to_int();
+        if (fn.nargs >= 3) gt.monthday = fn.arg(2).to_int();
       if (fn.nargs > 3) {
     IF_VERBOSE_ASCODING_ERRORS(
         log_aserror(_("Date.setYear was called with more than three 
arguments"));
@@ -830,7 +818,9 @@
 // the result is NAN.
 // We do not do the same because it's a bugger to code.
 
-static as_value _date_setmonth(const fn_call& fn, bool utc) {
+static as_value
+_date_setmonth(const fn_call& fn, bool utc)
+{
   boost::intrusive_ptr<date_as_object> date = 
ensureType<date_as_object>(fn.this_ptr);
 
   // assert(fn.nargs >= 1 && fn.nargs <= 2);
@@ -839,9 +829,11 @@
     log_aserror(_("Date.setMonth needs one argument"));
       )
       date->value = NAN;
-  } else if (rogue_date_args(fn, 2) != 0.0) {
+    }
+    else if (rogue_date_args(fn, 2) != 0.0) {
       date->value = NAN;
-  } else {
+    }
+    else {
 
       GnashTime gt;
 
@@ -859,7 +851,8 @@
     if (isnan(mdayvalue) || isinf(mdayvalue)) {
         date->value = NAN;
         return as_value(date->value);
-    } else {
+            }
+            else {
         gt.monthday = (int) mdayvalue;
     }
       }
@@ -879,7 +872,8 @@
 /// the first days of the following  month.  This also happens if you set the
 /// day > 31. Example: setting the 35th in January results in Feb 4th.
 
-static as_value _date_setdate(const fn_call& fn, bool utc) {
+static as_value
+_date_setdate(const fn_call& fn, bool utc) {
   boost::intrusive_ptr<date_as_object> date = 
ensureType<date_as_object>(fn.this_ptr);
 
   if (fn.nargs < 1) {
@@ -957,7 +951,9 @@
 /// or calendar day.
 /// Similarly, negative values carry you back into the previous 
minute/hour/day.
 
-static as_value _date_setminutes(const fn_call& fn, bool utc) {
+static as_value
+_date_setminutes(const fn_call& fn, bool utc)
+{
   boost::intrusive_ptr<date_as_object> date = 
ensureType<date_as_object>(fn.this_ptr);
 
   //assert(fn.nargs >= 1 && fn.nargs <= 3);
@@ -967,17 +963,17 @@
       )
       date->value = NAN;  // FlashPlayer instead leaves the date set to
         // a random value such as 9th December 2077 BC
-  } else if (rogue_date_args(fn, 3) != 0.0) {
+    }
+    else if (rogue_date_args(fn, 3) != 0.0) {
       date->value = NAN;
-  } else {
+    }
+    else {
       GnashTime gt;
 
       dateToGnashTime(*date, gt, utc);
       gt.minute = (int) fn.arg(0).to_number();
-      if (fn.nargs >= 2)
-        gt.second = (int) fn.arg(1).to_number();
-      if (fn.nargs >= 3)
-        gt.millisecond = (int) fn.arg(2).to_number();
+        if (fn.nargs >= 2) gt.second = (int) fn.arg(1).to_number();
+        if (fn.nargs >= 3) gt.millisecond = (int) fn.arg(2).to_number();
       if (fn.nargs > 3) {
     IF_VERBOSE_ASCODING_ERRORS(
         log_aserror(_("Date.setMinutes was called with more than three 
arguments"));
@@ -1028,7 +1024,9 @@
   return as_value(date->value);
 }
 
-static as_value date_setmilliseconds(const fn_call& fn) {
+static as_value
+date_setmilliseconds(const fn_call& fn)
+{
   boost::intrusive_ptr<date_as_object> date = 
ensureType<date_as_object>(fn.this_ptr);
 
   // assert(fn.nargs == 1);
@@ -1037,9 +1035,11 @@
     log_aserror(_("Date.setMilliseconds needs one argument"));
       )
       date->value = NAN;
-  } else if (rogue_date_args(fn, 1) != 0.0) {
+    }
+    else if (rogue_date_args(fn, 1) != 0.0) {
       date->value = NAN;
-  } else {
+    }
+    else {
       // Zero the milliseconds and set them from the argument.
       date->value = date->value - std::fmod(date->value, 1000.0) + 
fn.arg(0).to_int();
       if (fn.nargs > 1) {
@@ -1086,11 +1086,9 @@
 
 static as_value date_tostring(const fn_call& fn) {
 
-  boost::intrusive_ptr<date_as_object> 
-    date = ensureType<date_as_object>(fn.this_ptr);
-  
+    boost::intrusive_ptr<date_as_object> date = 
+                    ensureType<date_as_object>(fn.this_ptr);
   return date->toString();
-
 }
 
 // Date.UTC(year:Number,month[,day[,hour[,minute[,second[,millisecond]]]]]
@@ -1125,10 +1123,10 @@
 // non-numeric arguments we give NAN.
 
 
-static as_value date_utc(const fn_call& fn) {
+static as_value
+date_utc(const fn_call& fn) {
 
-
-  GnashTime gt; // Date structure for values down to seconds
+    GnashTime gt; // Date structure for values down to milliseconds
 
   if (fn.nargs < 2) {
       IF_VERBOSE_ASCODING_ERRORS(
@@ -1187,7 +1185,8 @@
 // plus (or minus) infinity if positive (or negative) infinites are present,
 // NAN is there are NANs present, or a mixture of positive and negative infs.
 static double
-rogue_date_args(const fn_call& fn, unsigned maxargs) {
+rogue_date_args(const fn_call& fn, unsigned maxargs)
+{
   // Two flags: Did we find any +Infinity (or -Infinity) values in the
   // argument list? If so, "infinity" must be set to the kind that we
   // found.
@@ -1207,7 +1206,8 @@
     if (isinf(arg)) {
       if (arg > 0) {  // Plus infinity
         plusinf = true;
-      } else {  // Minus infinity
+            }
+            else {  // Minus infinity
         minusinf = true;
       }
       // Remember the kind of infinity we found
@@ -1229,28 +1229,27 @@
 /// \brief Date.valueOf() returns the number of milliseconds since midnight
 /// January 1, 1970 00:00 UTC, for a Date. The return value can be a fractional
 /// number of milliseconds.
-
-static as_value date_valueof(const fn_call& fn) {
+static as_value
+date_valueof(const fn_call& fn)
+{
   boost::intrusive_ptr<date_as_object> date = 
ensureType<date_as_object>(fn.this_ptr);
-
     return as_value(date->value);
 }
 
 
-static as_value date_gettime(const fn_call& fn) {
+static as_value date_gettime(const fn_call& fn)
+{
   boost::intrusive_ptr<date_as_object> date = 
ensureType<date_as_object>(fn.this_ptr);
-  
   return as_value(date->value);
 }
 
 // extern (used by Global.cpp)
 void date_class_init(as_object& global)
 {
-  // This is going to be the global String "class"/"function"
+    // This is going to be the global Date "class"/"function"
   static boost::intrusive_ptr<builtin_function> cl;
 
-  if ( cl == NULL )
-  {
+    if ( cl == NULL ) {
     cl=new builtin_function(&date_new, getDateInterface());
     // replicate all interface to class, to be able to access
     // all methods as static functions
@@ -1262,6 +1261,12 @@
 
 }
 
+///
+///
+/// Date conversion functions
+///
+///
+
 // Converts a time struct into a flash timestamp. Similar to
 // mktime, but not limited by the size of time_t. The mathematical
 // algorithm looks nicer, but does not cope with large dates.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]