[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r9922: Remove macros from Date.cpp.
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r9922: Remove macros from Date.cpp. |
Date: |
Sat, 04 Oct 2008 15:39:02 +0200 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9922
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Sat 2008-10-04 15:39:02 +0200
message:
Remove macros from Date.cpp.
modified:
libcore/asobj/Date.cpp
------------------------------------------------------------
revno: 9911.1.8
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Sat 2008-10-04 13:38:39 +0200
message:
Replace macro for set* methods with template. Will generate more code and
fewer function lookups.
modified:
libcore/asobj/Date.cpp
------------------------------------------------------------
revno: 9911.1.9
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Sat 2008-10-04 14:15:11 +0200
message:
Rename file-scope functions.
modified:
libcore/asobj/Date.cpp
------------------------------------------------------------
revno: 9911.1.10
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Sat 2008-10-04 14:25:36 +0200
message:
Minor formatting change.
modified:
libcore/asobj/Date.cpp
=== modified file 'libcore/asobj/Date.cpp'
--- a/libcore/asobj/Date.cpp 2008-10-04 09:55:12 +0000
+++ b/libcore/asobj/Date.cpp 2008-10-04 12:25:36 +0000
@@ -107,7 +107,46 @@
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
+// Seconds and milliseconds should be exactly the same whether in UTC
+// or in localtime, so we always use localtime.
+
// forward declarations
+static as_object* getDateInterface();
+static void attachDateInterface(as_object& o);
+static void attachDateStaticInterface(as_object& o);
+
+static as_value date_new(const fn_call& fn);
+static as_value date_getTime(const fn_call& fn);
+static as_value date_setTime(const fn_call& fn);
+static as_value date_getTimezoneOffset(const fn_call& fn);
+static as_value date_getYear(const fn_call& fn);
+static as_value date_getFullYear(const fn_call& fn);
+static as_value date_getMonth(const fn_call& fn);
+static as_value date_getDate(const fn_call& fn);
+static as_value date_getDay(const fn_call& fn);
+static as_value date_getHours(const fn_call& fn);
+static as_value date_getMinutes(const fn_call& fn);
+static as_value date_getSeconds(const fn_call& fn);
+static as_value date_getMilliseconds(const fn_call& fn);
+static as_value date_getUTCFullYear(const fn_call& fn);
+static as_value date_getUTCYear(const fn_call& fn);
+static as_value date_getUTCMonth(const fn_call& fn);
+static as_value date_getutcdate(const fn_call& fn);
+static as_value date_getUTCDay(const fn_call& fn);
+static as_value date_getUTCHours(const fn_call& fn);
+static as_value date_getUTCMinutes(const fn_call& fn);
+template<bool utc> as_value date_setDate(const fn_call& fn);
+template<bool utc> as_value date_setfullyear(const fn_call& fn);
+template<bool utc> as_value date_setHours(const fn_call& fn);
+template<bool utc> as_value date_setMilliseconds(const fn_call& fn);
+template<bool utc> as_value date_setMinutes(const fn_call& fn);
+template<bool utc> as_value date_setmonth(const fn_call& fn);
+template<bool utc> as_value date_setSeconds(const fn_call& fn);
+static as_value date_setYear(const fn_call& fn);
+static as_value date_tostring(const fn_call& fn);
+static as_value date_valueof(const fn_call& fn);
+static as_value date_UTC(const fn_call& fn);
+
static void fillGnashTime(const double& time, GnashTime& gt);
static double makeTimeValue(GnashTime& gt);
static void localTime(const double& time, GnashTime& gt);
@@ -116,12 +155,21 @@
static double rogue_date_args(const fn_call& fn, unsigned maxargs);
-// Helper macros for calendar algorithms
-#define IS_LEAP_YEAR(n) ( !((n + 1900) % 400) || ( !((n + 1900) % 4) && ((n +
1900) % 100)) )
-
-// Count the leap years. This needs some adjustment
-// to get the actual number
-#define COUNT_LEAP_YEARS(n) ( (n - 70) / 4 - (n - 70) / 100 + (n - 70) / 400
)
+// Helpers for calendar algorithms
+inline bool
+isLeapYear(boost::int32_t year)
+{
+ return !((year + 1900) % 400) ||
+ ( !((year + 1900) % 4) && ((year + 1900) % 100));
+}
+
+
+inline size_t
+countLeapYears(boost::int32_t year)
+{
+ return (year - 70) / 4 - (year - 70) / 100 + (year - 70) / 400;
+}
+
class Date : public as_object
{
@@ -129,7 +177,12 @@
void setTimeValue(const double& value) { _value = value; }
double getTimeValue() const { return _value; }
- Date(double value = clocktime::getTicks());
+ Date(double value = clocktime::getTicks())
+ :
+ as_object(getDateInterface()),
+ _value(value)
+ {
+ }
as_value toString() const;
@@ -173,105 +226,55 @@
}
-
-// Seconds and milliseconds should be exactly the same whether in UTC
-// or in localtime, so we always use localtime.
-
-// forward declarations
-static as_object* getDateInterface();
-static void attachDateInterface(as_object& o);
-static void attachDateStaticInterface(as_object& o);
-
-static as_value date_new(const fn_call& fn);
-static as_value date_gettime(const fn_call& fn);
-static as_value date_settime(const fn_call& fn);
-static as_value date_gettimezoneoffset(const fn_call& fn);
-static as_value date_getyear(const fn_call& fn);
-static as_value date_getfullyear(const fn_call& fn);
-static as_value date_getmonth(const fn_call& fn);
-static as_value date_getdate(const fn_call& fn);
-static as_value date_getday(const fn_call& fn);
-static as_value date_gethours(const fn_call& fn);
-static as_value date_getminutes(const fn_call& fn);
-static as_value date_getseconds(const fn_call& fn);
-static as_value date_getmilliseconds(const fn_call& fn);
-static as_value date_getutcfullyear(const fn_call& fn);
-static as_value date_getutcyear(const fn_call& fn);
-static as_value date_getutcmonth(const fn_call& fn);
-static as_value date_getutcdate(const fn_call& fn);
-static as_value date_getutcday(const fn_call& fn);
-static as_value date_getutchours(const fn_call& fn);
-static as_value date_getutcminutes(const fn_call& fn);
-static as_value date_setdate(const fn_call& fn);
-static as_value date_setfullyear(const fn_call& fn);
-static as_value date_sethours(const fn_call& fn);
-static as_value date_setmilliseconds(const fn_call& fn);
-static as_value date_setutcseconds(const fn_call& fn);
-static as_value date_setutcmilliseconds(const fn_call& fn);
-static as_value date_setminutes(const fn_call& fn);
-static as_value date_setmonth(const fn_call& fn);
-static as_value date_setseconds(const fn_call& fn);
-static as_value date_setutcdate(const fn_call& fn);
-static as_value date_setutcfullyear(const fn_call& fn);
-static as_value date_setutchours(const fn_call& fn);
-static as_value date_setutcminutes(const fn_call& fn);
-static as_value date_setutcmonth(const fn_call& fn);
-static as_value date_setyear(const fn_call& fn);
-static as_value date_tostring(const fn_call& fn);
-static as_value date_valueof(const fn_call& fn);
-
-// Static AS methods
-static as_value date_utc(const fn_call& fn);
-
void registerDateNative(as_object& global)
{
VM& vm = global.getVM();
- vm.registerNative(date_getfullyear, 103, 0);
- vm.registerNative(date_getyear, 103, 1);
- vm.registerNative(date_getmonth, 103, 2);
- vm.registerNative(date_getdate, 103, 3);
- vm.registerNative(date_getday, 103, 4);
- vm.registerNative(date_gethours, 103, 5);
- vm.registerNative(date_getminutes, 103, 6);
- vm.registerNative(date_getseconds, 103, 7);
- vm.registerNative(date_getmilliseconds, 103, 8);
- vm.registerNative(date_setfullyear, 103, 9);
- vm.registerNative(date_setmonth, 103, 10);
- vm.registerNative(date_setdate, 103, 11);
- vm.registerNative(date_sethours, 103, 12);
- vm.registerNative(date_setminutes, 103, 13);
- vm.registerNative(date_setseconds, 103, 14);
- vm.registerNative(date_setmilliseconds, 103, 15);
- vm.registerNative(date_gettime, 103, 16);
- vm.registerNative(date_settime, 103, 17);
- vm.registerNative(date_gettimezoneoffset, 103, 18);
+ vm.registerNative(date_getFullYear, 103, 0);
+ vm.registerNative(date_getYear, 103, 1);
+ vm.registerNative(date_getMonth, 103, 2);
+ vm.registerNative(date_getDate, 103, 3);
+ vm.registerNative(date_getDay, 103, 4);
+ vm.registerNative(date_getHours, 103, 5);
+ vm.registerNative(date_getMinutes, 103, 6);
+ vm.registerNative(date_getSeconds, 103, 7);
+ vm.registerNative(date_getMilliseconds, 103, 8);
+ vm.registerNative(date_setfullyear<false>, 103, 9);
+ vm.registerNative(date_setmonth<false>, 103, 10);
+ vm.registerNative(date_setDate<false>, 103, 11);
+ vm.registerNative(date_setHours<false>, 103, 12);
+ vm.registerNative(date_setMinutes<false>, 103, 13);
+ vm.registerNative(date_setSeconds<false>, 103, 14);
+ vm.registerNative(date_setMilliseconds<false>, 103, 15);
+ vm.registerNative(date_getTime, 103, 16);
+ vm.registerNative(date_setTime, 103, 17);
+ vm.registerNative(date_getTimezoneOffset, 103, 18);
vm.registerNative(date_tostring, 103, 19);
- vm.registerNative(date_setyear, 103, 20);
- vm.registerNative(date_getutcfullyear, 103, 128);
- vm.registerNative(date_getutcyear, 103, 129);
- vm.registerNative(date_getutcmonth, 103, 130);
+ vm.registerNative(date_setYear, 103, 20);
+ vm.registerNative(date_getUTCFullYear, 103, 128);
+ vm.registerNative(date_getUTCYear, 103, 129);
+ vm.registerNative(date_getUTCMonth, 103, 130);
vm.registerNative(date_getutcdate, 103, 131);
- vm.registerNative(date_getutcday, 103, 132);
- vm.registerNative(date_getutchours, 103, 133);
- vm.registerNative(date_getutcminutes, 103, 134);
+ vm.registerNative(date_getUTCDay, 103, 132);
+ vm.registerNative(date_getUTCHours, 103, 133);
+ vm.registerNative(date_getUTCMinutes, 103, 134);
// These two are deliberately the same as non-UTC methods
// as there should be no difference:
- vm.registerNative(date_getseconds, 103, 135);
- vm.registerNative(date_getmilliseconds, 103, 136);
+ vm.registerNative(date_getSeconds, 103, 135);
+ vm.registerNative(date_getMilliseconds, 103, 136);
- vm.registerNative(date_setutcfullyear, 103, 137);
- vm.registerNative(date_setutcmonth, 103, 138);
- vm.registerNative(date_setutcdate, 103, 139);
- vm.registerNative(date_setutchours, 103, 140);
- vm.registerNative(date_setutcminutes, 103, 141);
- vm.registerNative(date_setutcseconds, 103, 142);
- vm.registerNative(date_setutcmilliseconds, 103, 143);
+ vm.registerNative(date_setfullyear<true>, 103, 137);
+ vm.registerNative(date_setmonth<true>, 103, 138);
+ vm.registerNative(date_setDate<true>, 103, 139);
+ vm.registerNative(date_setHours<true>, 103, 140);
+ vm.registerNative(date_setMinutes<true>, 103, 141);
+ vm.registerNative(date_setSeconds<true>, 103, 142);
+ vm.registerNative(date_setMilliseconds<true>, 103, 143);
//vm.registerNative(date_new, 103, 256);
- vm.registerNative(date_utc, 103, 257);
+ vm.registerNative(date_UTC, 103, 257);
}
@@ -345,14 +348,6 @@
}
-Date::Date(double value)
- :
- as_object(getDateInterface()),
- _value(value)
-{
-}
-
-
as_value
Date::toString() const
{
@@ -381,7 +376,7 @@
// If timezone is negative, both hours and minutes will be negative
// but for the purpose of printing a string, only the hour needs to
// produce a minus sign.
- if (offsetMinutes < 0) offsetMinutes = - offsetMinutes;
+ if (offsetMinutes < 0) offsetMinutes = -offsetMinutes;
boost::format dateFormat("%s %s %d %02d:%02d:%02d GMT%+03d%02d %d");
dateFormat % dayweekname[gt.weekday] % monthname[gt.month]
@@ -417,7 +412,7 @@
// 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) {
+ if (( foo = rogue_date_args(fn, 7)) != 0.0) {
date = new Date(foo);
return as_value(date.get());
}
@@ -524,7 +519,7 @@
//
/// Returns a Date's Gregorian year minus 1900 according to local time.
static as_value
-date_getyear(const fn_call& fn)
+date_getYear(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(localTime, &GnashTime::year, date->getTimeValue());
@@ -533,16 +528,17 @@
/// \brief Date.getFullYear
/// returns a Date's Gregorian year according to local time.
static as_value
-date_getfullyear(const fn_call& fn)
+date_getFullYear(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
- return timeElement(localTime, &GnashTime::year, date->getTimeValue(),
1900);
+ return timeElement(
+ localTime, &GnashTime::year, date->getTimeValue(), 1900);
}
/// \brief Date.getMonth
/// returns a Date's month in the range 0 to 11.
static as_value
-date_getmonth(const fn_call& fn)
+date_getMonth(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(localTime, &GnashTime::month, date->getTimeValue());
@@ -551,7 +547,7 @@
/// \brief Date.getDate
/// returns a Date's day-of-month, from 1 to 31 according to local time.
static as_value
-date_getdate(const fn_call& fn)
+date_getDate(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(localTime, &GnashTime::monthday, date->getTimeValue());
@@ -561,7 +557,7 @@
/// returns the day of the week for a Date according to local time,
/// where 0 is Sunday and 6 is Saturday.
static as_value
-date_getday(const fn_call& fn)
+date_getDay(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(localTime, &GnashTime::weekday, date->getTimeValue());
@@ -571,7 +567,7 @@
/// \brief Date.getHours
/// Returns the hour number for a Date, from 0 to 23, according to local time.
static as_value
-date_gethours(const fn_call& fn)
+date_getHours(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(localTime, &GnashTime::hour, date->getTimeValue());
@@ -582,7 +578,7 @@
/// (Yes, some places do have a fractions of an hour's timezone offset
/// or daylight saving time!)
static as_value
-date_getminutes(const fn_call& fn)
+date_getMinutes(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(localTime, &GnashTime::minute, date->getTimeValue());
@@ -592,7 +588,7 @@
/// returns a Date's seconds, from 0-59.
/// Localtime should be irrelevant.
static as_value
-date_getseconds(const fn_call& fn)
+date_getSeconds(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(localTime, &GnashTime::second, date->getTimeValue());
@@ -604,7 +600,7 @@
//
// Also implements Date.getUTCMilliseconds
static as_value
-date_getmilliseconds(const fn_call& fn)
+date_getMilliseconds(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(
@@ -615,7 +611,7 @@
// The same functions for universal time.
//
static as_value
-date_getutcfullyear(const fn_call& fn)
+date_getUTCFullYear(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(universalTime, &GnashTime::year,
@@ -623,14 +619,14 @@
}
static as_value
-date_getutcyear(const fn_call& fn)
+date_getUTCYear(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(universalTime, &GnashTime::year, date->getTimeValue());
}
static as_value
-date_getutcmonth(const fn_call& fn)
+date_getUTCMonth(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(universalTime, &GnashTime::month, date->getTimeValue());
@@ -646,7 +642,7 @@
static as_value
-date_getutcday(const fn_call& fn)
+date_getUTCDay(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(
@@ -654,7 +650,7 @@
}
static as_value
-date_getutchours(const fn_call& fn)
+date_getUTCHours(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(
@@ -662,7 +658,7 @@
}
static as_value
-date_getutcminutes(const fn_call& fn)
+date_getUTCMinutes(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return timeElement(universalTime, &GnashTime::minute,
date->getTimeValue());
@@ -670,7 +666,8 @@
// Return the difference between UTC and localtime in minutes.
-inline int localTimeZoneOffset(const double& time)
+inline int
+localTimeZoneOffset(const double& time)
{
// This simply has to return the difference in minutes
// between UTC (Greenwich Mean Time, GMT) and the localtime.
@@ -684,7 +681,7 @@
/// time specified by a Date object, according to local timezone and DST.
/// For example, if you are in GMT+0100, the offset is -60
static as_value
-date_gettimezoneoffset(const fn_call& fn)
+date_getTimezoneOffset(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return as_value(-localTimeZoneOffset(date->getTimeValue()));
@@ -699,7 +696,7 @@
/// 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)
+date_setTime(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
@@ -799,7 +796,10 @@
// Heaven knows what happens if it is 1.30 localtime and you change the date
// to the day the clocks go forward.
-static as_value _date_setfullyear(const fn_call& fn, bool utc) {
+template<bool utc>
+as_value
+date_setfullyear(const fn_call& fn)
+{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
if (fn.nargs < 1) {
@@ -819,9 +819,10 @@
if (fn.nargs >= 3)
gt.monthday = fn.arg(2).to_int();
if (fn.nargs > 3) {
- IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setFullYear was called with more than three
arguments"));
- )
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(_("Date.set%sFullYear was called with "
+ "more than three arguments"), utc ? "UTC" : "");
+ )
}
gnashTimeToDate(gt, *date, utc);
}
@@ -843,7 +844,7 @@
//
// There is no setUTCYear() function.
static as_value
-date_setyear(const fn_call& fn)
+date_setYear(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
@@ -892,15 +893,17 @@
// Only if the second parameter is present and has a non-numeric value,
// 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)
+template<bool utc>
+as_value
+date_setmonth(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
// assert(fn.nargs >= 1 && fn.nargs <= 2);
if (fn.nargs < 1) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setMonth needs one argument"));
+ log_aserror(_("Date.set%sMonth needs one argument"),
+ utc ? "UTC" : "");
)
date->setTimeValue(NaN);
}
@@ -932,8 +935,8 @@
}
if (fn.nargs > 2) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setMonth was called with more than three "
- "arguments"));
+ log_aserror(_("Date.set%sMonth was called with more than three
"
+ "arguments"), utc ? "UTC" : "");
)
}
gnashTimeToDate(gt, *date, utc);
@@ -946,13 +949,15 @@
/// If the day-of-month is beyond the end of the current month, it wraps into
/// 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) {
+template<bool utc>
+as_value
+date_setDate(const fn_call& fn)
+{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
if (fn.nargs < 1) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setDate needs one argument"));
+ log_aserror(_("Date.set%sDate needs one argument"), utc ? "UTC" : "");
)
date->setTimeValue(NaN); // Is what FlashPlayer sets
} else if (rogue_date_args(fn, 1) != 0.0) {
@@ -966,7 +971,8 @@
}
if (fn.nargs > 1) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setDate was called with more than one argument"));
+ log_aserror(_("Date.set%sDate was called with more than one argument"),
+ utc ? "UTC" : "");
)
}
return as_value(date->getTimeValue());
@@ -983,15 +989,17 @@
/// Only the integer part of millisec is used, truncating it, not rounding it.
/// The only way to set a fractional number of milliseconds is to use
/// setTime(n) or call the constructor with one argument.
-static as_value
-_date_sethours(const fn_call& fn, bool utc)
+template<bool utc>
+as_value
+date_setHours(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
// assert(fn.nargs >= 1 && fn.nargs <= 4);
if (fn.nargs < 1) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setHours needs one argument"));
+ log_aserror(_("Date.set%sHours needs one argument"),
+ utc ? "UTC" : "");
)
date->setTimeValue(NaN); // Is what FlashPlayer sets
}
@@ -1009,7 +1017,8 @@
if (fn.nargs >= 4) gt.millisecond = fn.arg(3).to_int();
if (fn.nargs > 4) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setHours was called with more than four
arguments"));
+ log_aserror(_("Date.set%sHours was called with more than "
+ "four arguments"), utc ? "UTC" : "");
)
}
@@ -1025,16 +1034,17 @@
/// If min/sec>59, these are accepted and wrap into the following minute, hour
/// 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)
+template<bool utc>
+as_value
+date_setMinutes(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
//assert(fn.nargs >= 1 && fn.nargs <= 3);
if (fn.nargs < 1) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setMinutes needs one argument"));
+ log_aserror(_("Date.set%sMinutes needs one argument"),
+ utc ? "UTC" : "");
)
date->setTimeValue(NaN); // FlashPlayer instead leaves the date set to
// a random value such as 9th December 2077 BC
@@ -1051,7 +1061,8 @@
if (fn.nargs >= 3) gt.millisecond = fn.arg(2).to_int();
if (fn.nargs > 3) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setMinutes was called with more than three
arguments"));
+ log_aserror(_("Date.set%sMinutes was called with more than "
+ "three arguments"), utc ? "UTC" : "");
)
}
gnashTimeToDate(gt, *date, utc);
@@ -1064,15 +1075,17 @@
///
/// Values <0, >59 for secs or >999 for millisecs take the date back to the
/// previous minute (or hour or calendar day) or on to the following ones.
-static as_value
-_date_setseconds(const fn_call& fn, bool utc)
+template<bool utc>
+as_value
+date_setSeconds(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
// assert(fn.nargs >= 1 && fn.nargs <= 2);
if (fn.nargs < 1) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setSeconds needs one argument"));
+ log_aserror(_("Date.set%sSeconds needs one argument"),
+ utc ? "UTC" : "");
)
date->setTimeValue(NaN); // Same as commercial player
}
@@ -1091,26 +1104,26 @@
if (fn.nargs >= 2) gt.millisecond = fn.arg(1).to_int();
if (fn.nargs > 2) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setMinutes was called with more than three
arguments"));
+ log_aserror(_("Date.set%sMinutes was called with more than "
+ "three arguments"), utc ? "UTC" : "");
)
}
- // This is both setSeconds and setUTCSeconds.
- // Use utc to avoid needless worrying about timezones.
gnashTimeToDate(gt, *date, utc);
}
return as_value(date->getTimeValue());
}
-static as_value
-_date_setmilliseconds(const fn_call& fn, bool utc)
+template<bool utc>
+as_value
+date_setMilliseconds(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
- // assert(fn.nargs == 1);
if (fn.nargs < 1) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setMilliseconds needs one argument"));
+ log_aserror(_("Date.set%sMilliseconds needs one argument"),
+ utc ? "UTC" : "");
)
date->setTimeValue(NaN);
}
@@ -1126,7 +1139,8 @@
if (fn.nargs > 1) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Date.setMilliseconds was called with more than
one argument"));
+ log_aserror(_("Date.setMilliseconds was called with more "
+ "than one argument"), utc ? "UTC" : "");
)
}
@@ -1138,36 +1152,6 @@
return as_value(date->getTimeValue());
}
-// Bindings for localtime versions
-#define local_proto(item) \
- static as_value date_set##item(const fn_call& fn) { \
- _date_set##item(fn, false); \
- return as_value(); \
- }
-local_proto(fullyear)
-local_proto(month)
-local_proto(date)
-local_proto(hours)
-local_proto(minutes)
-local_proto(seconds)
-local_proto(milliseconds)
-#undef local_proto
-
-// The same things for UTC.
-#define utc_proto(item) \
- static as_value date_setutc##item(const fn_call& fn) { \
- _date_set##item(fn, true); \
- return as_value(); \
- }
-utc_proto(fullyear)
-utc_proto(month)
-utc_proto(date)
-utc_proto(hours)
-utc_proto(minutes)
-utc_proto(seconds)
-utc_proto(milliseconds)
-#undef utc_proto
-
/// \brief Date.toString()
/// convert a Date to a printable string.
@@ -1210,10 +1194,8 @@
//
// We test for < 2 parameters and return undefined, but given any other
// non-numeric arguments we give NaN.
-
-
static as_value
-date_utc(const fn_call& fn) {
+date_UTC(const fn_call& fn) {
GnashTime gt; // Date structure for values down to milliseconds
@@ -1327,7 +1309,7 @@
}
-static as_value date_gettime(const fn_call& fn)
+static as_value date_getTime(const fn_call& fn)
{
boost::intrusive_ptr<Date> date = ensureType<Date>(fn.this_ptr);
return as_value(date->getTimeValue());
@@ -1387,19 +1369,19 @@
// This works but is a bit clunky.
if (t.year < 70) {
- day = COUNT_LEAP_YEARS(t.year - 2) + ((t.year - 70) * 365);
+ day = countLeapYears(t.year - 2) + ((t.year - 70) * 365);
// Adds an extra leap year for the year 0.
if (t.year <= 0) day++;
}
else {
- day = COUNT_LEAP_YEARS(t.year + 1) + ((t.year - 70) * 365);
+ day = countLeapYears(t.year + 1) + ((t.year - 70) * 365);
}
// Add days for each month. Month must be 0 - 11;
for (int i = 0; i < t.month; i++)
{
assert (t.month < 12);
- day += daysInMonth[IS_LEAP_YEAR (t.year)][i];
+ day += daysInMonth[isLeapYear(t.year)][i];
}
// Add the days of the month
@@ -1432,7 +1414,7 @@
{
for (;;)
{
- bool isleap = IS_LEAP_YEAR(year - 1900);
+ bool isleap = isLeapYear(year - 1900);
if (days < (isleap ? 366 : 365)) break;
year++;
days -= isleap ? 366 : 365;
@@ -1443,7 +1425,7 @@
do
{
--year;
- bool isleap = IS_LEAP_YEAR(year - 1900);
+ bool isleap = isLeapYear(year - 1900);
days += isleap ? 366 : 365;
} while (days < 0);
}
@@ -1481,10 +1463,10 @@
if (time < 0)
{
- if (gt.millisecond < 0) { gt.millisecond += 1000; gt.second--; }
- if (gt.second < 0) { gt.second += 60; gt.minute--; }
- if (gt.minute < 0) { gt.minute += 60; gt.hour--; }
- if (gt.hour < 0) { gt.hour += 24; days--; }
+ if (gt.millisecond < 0) { gt.millisecond += 1000; --gt.second; }
+ if (gt.second < 0) { gt.second += 60; --gt.minute; }
+ if (gt.minute < 0) { gt.minute += 60; --gt.hour; }
+ if (gt.hour < 0) { gt.hour += 24; --days; }
}
if (days >= -4) gt.weekday = (days + 4) % 7;
@@ -1496,12 +1478,12 @@
gt.month = 0;
for (int i = 0; i < 12; ++i)
{
- if (days - daysInMonth[IS_LEAP_YEAR (gt.year)][i] < 0)
+ if (days - daysInMonth[isLeapYear(gt.year)][i] < 0)
{
gt.month = i;
break;
}
- days -= daysInMonth[IS_LEAP_YEAR (gt.year)][i];
+ days -= daysInMonth[isLeapYear(gt.year)][i];
}
gt.monthday = days + 1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r9922: Remove macros from Date.cpp.,
Benjamin Wolsey <=