| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtScript module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qscriptecmadate_p.h"
|
|---|
| 43 |
|
|---|
| 44 | #ifndef QT_NO_SCRIPT
|
|---|
| 45 |
|
|---|
| 46 | #include "qscriptengine_p.h"
|
|---|
| 47 | #include "qscriptvalueimpl_p.h"
|
|---|
| 48 | #include "qscriptcontext_p.h"
|
|---|
| 49 | #include "qscriptmember_p.h"
|
|---|
| 50 | #include "qscriptobject_p.h"
|
|---|
| 51 |
|
|---|
| 52 | #include <QtCore/QDateTime>
|
|---|
| 53 | #include <QtCore/QRegExp>
|
|---|
| 54 | #include <QtCore/QtDebug>
|
|---|
| 55 | #include <QtCore/QLocale>
|
|---|
| 56 | #include <QtCore/qnumeric.h>
|
|---|
| 57 |
|
|---|
| 58 | #include <math.h>
|
|---|
| 59 |
|
|---|
| 60 | #ifndef Q_WS_WIN
|
|---|
| 61 | # include <time.h>
|
|---|
| 62 | # include <sys/time.h>
|
|---|
| 63 | #else
|
|---|
| 64 | # include <windows.h>
|
|---|
| 65 | #endif
|
|---|
| 66 |
|
|---|
| 67 | QT_BEGIN_NAMESPACE
|
|---|
| 68 |
|
|---|
| 69 | namespace QScript {
|
|---|
| 70 |
|
|---|
| 71 | static const qsreal HoursPerDay = 24.0;
|
|---|
| 72 | static const qsreal MinutesPerHour = 60.0;
|
|---|
| 73 | static const qsreal SecondsPerMinute = 60.0;
|
|---|
| 74 | static const qsreal msPerSecond = 1000.0;
|
|---|
| 75 | static const qsreal msPerMinute = 60000.0;
|
|---|
| 76 | static const qsreal msPerHour = 3600000.0;
|
|---|
| 77 | static const qsreal msPerDay = 86400000.0;
|
|---|
| 78 |
|
|---|
| 79 | static qsreal LocalTZA = 0.0; // initialized at startup
|
|---|
| 80 |
|
|---|
| 81 | static inline qsreal TimeWithinDay(qsreal t)
|
|---|
| 82 | {
|
|---|
| 83 | qsreal r = ::fmod(t, msPerDay);
|
|---|
| 84 | return (r >= 0) ? r : r + msPerDay;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | static inline int HourFromTime(qsreal t)
|
|---|
| 88 | {
|
|---|
| 89 | int r = int(::fmod(::floor(t / msPerHour), HoursPerDay));
|
|---|
| 90 | return (r >= 0) ? r : r + int(HoursPerDay);
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | static inline int MinFromTime(qsreal t)
|
|---|
| 94 | {
|
|---|
| 95 | int r = int(::fmod(::floor(t / msPerMinute), MinutesPerHour));
|
|---|
| 96 | return (r >= 0) ? r : r + int(MinutesPerHour);
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | static inline int SecFromTime(qsreal t)
|
|---|
| 100 | {
|
|---|
| 101 | int r = int(::fmod(::floor(t / msPerSecond), SecondsPerMinute));
|
|---|
| 102 | return (r >= 0) ? r : r + int(SecondsPerMinute);
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | static inline int msFromTime(qsreal t)
|
|---|
| 106 | {
|
|---|
| 107 | int r = int(::fmod(t, msPerSecond));
|
|---|
| 108 | return (r >= 0) ? r : r + int(msPerSecond);
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | static inline qsreal Day(qsreal t)
|
|---|
| 112 | {
|
|---|
| 113 | return ::floor(t / msPerDay);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | static inline qsreal DaysInYear(qsreal y)
|
|---|
| 117 | {
|
|---|
| 118 | if (::fmod(y, 4))
|
|---|
| 119 | return 365;
|
|---|
| 120 |
|
|---|
| 121 | else if (::fmod(y, 100))
|
|---|
| 122 | return 366;
|
|---|
| 123 |
|
|---|
| 124 | else if (::fmod(y, 400))
|
|---|
| 125 | return 365;
|
|---|
| 126 |
|
|---|
| 127 | return 366;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | static inline qsreal DayFromYear(qsreal y)
|
|---|
| 131 | {
|
|---|
| 132 | return 365 * (y - 1970)
|
|---|
| 133 | + ::floor((y - 1969) / 4)
|
|---|
| 134 | - ::floor((y - 1901) / 100)
|
|---|
| 135 | + ::floor((y - 1601) / 400);
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | static inline qsreal TimeFromYear(qsreal y)
|
|---|
| 139 | {
|
|---|
| 140 | return msPerDay * DayFromYear(y);
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | static inline qsreal YearFromTime(qsreal t)
|
|---|
| 144 | {
|
|---|
| 145 | int y = 1970;
|
|---|
| 146 | y += (int) ::floor(t / (msPerDay * 365.2425));
|
|---|
| 147 |
|
|---|
| 148 | qsreal t2 = TimeFromYear(y);
|
|---|
| 149 | return (t2 > t) ? y - 1 : ((t2 + msPerDay * DaysInYear(y)) <= t) ? y + 1 : y;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | static inline bool InLeapYear(qsreal t)
|
|---|
| 153 | {
|
|---|
| 154 | qsreal x = DaysInYear(YearFromTime(t));
|
|---|
| 155 | if (x == 365)
|
|---|
| 156 | return 0;
|
|---|
| 157 |
|
|---|
| 158 | Q_ASSERT (x == 366);
|
|---|
| 159 | return 1;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | static inline qsreal DayWithinYear(qsreal t)
|
|---|
| 163 | {
|
|---|
| 164 | return Day(t) - DayFromYear(YearFromTime(t));
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | static inline qsreal MonthFromTime(qsreal t)
|
|---|
| 168 | {
|
|---|
| 169 | qsreal d = DayWithinYear(t);
|
|---|
| 170 | qsreal l = InLeapYear(t);
|
|---|
| 171 |
|
|---|
| 172 | if (d < 31.0)
|
|---|
| 173 | return 0;
|
|---|
| 174 |
|
|---|
| 175 | else if (d < 59.0 + l)
|
|---|
| 176 | return 1;
|
|---|
| 177 |
|
|---|
| 178 | else if (d < 90.0 + l)
|
|---|
| 179 | return 2;
|
|---|
| 180 |
|
|---|
| 181 | else if (d < 120.0 + l)
|
|---|
| 182 | return 3;
|
|---|
| 183 |
|
|---|
| 184 | else if (d < 151.0 + l)
|
|---|
| 185 | return 4;
|
|---|
| 186 |
|
|---|
| 187 | else if (d < 181.0 + l)
|
|---|
| 188 | return 5;
|
|---|
| 189 |
|
|---|
| 190 | else if (d < 212.0 + l)
|
|---|
| 191 | return 6;
|
|---|
| 192 |
|
|---|
| 193 | else if (d < 243.0 + l)
|
|---|
| 194 | return 7;
|
|---|
| 195 |
|
|---|
| 196 | else if (d < 273.0 + l)
|
|---|
| 197 | return 8;
|
|---|
| 198 |
|
|---|
| 199 | else if (d < 304.0 + l)
|
|---|
| 200 | return 9;
|
|---|
| 201 |
|
|---|
| 202 | else if (d < 334.0 + l)
|
|---|
| 203 | return 10;
|
|---|
| 204 |
|
|---|
| 205 | else if (d < 365.0 + l)
|
|---|
| 206 | return 11;
|
|---|
| 207 |
|
|---|
| 208 | return qSNaN(); // ### assert?
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | static inline qsreal DateFromTime(qsreal t)
|
|---|
| 212 | {
|
|---|
| 213 | int m = (int) QScriptEnginePrivate::toInteger(MonthFromTime(t));
|
|---|
| 214 | qsreal d = DayWithinYear(t);
|
|---|
| 215 | qsreal l = InLeapYear(t);
|
|---|
| 216 |
|
|---|
| 217 | switch (m) {
|
|---|
| 218 | case 0: return d + 1.0;
|
|---|
| 219 | case 1: return d - 30.0;
|
|---|
| 220 | case 2: return d - 58.0 - l;
|
|---|
| 221 | case 3: return d - 89.0 - l;
|
|---|
| 222 | case 4: return d - 119.0 - l;
|
|---|
| 223 | case 5: return d - 150.0 - l;
|
|---|
| 224 | case 6: return d - 180.0 - l;
|
|---|
| 225 | case 7: return d - 211.0 - l;
|
|---|
| 226 | case 8: return d - 242.0 - l;
|
|---|
| 227 | case 9: return d - 272.0 - l;
|
|---|
| 228 | case 10: return d - 303.0 - l;
|
|---|
| 229 | case 11: return d - 333.0 - l;
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | return qSNaN(); // ### assert
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | static inline qsreal WeekDay(qsreal t)
|
|---|
| 236 | {
|
|---|
| 237 | qsreal r = ::fmod (Day(t) + 4.0, 7.0);
|
|---|
| 238 | return (r >= 0) ? r : r + 7.0;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 | static inline qsreal MakeTime(qsreal hour, qsreal min, qsreal sec, qsreal ms)
|
|---|
| 243 | {
|
|---|
| 244 | return ((hour * MinutesPerHour + min) * SecondsPerMinute + sec) * msPerSecond + ms;
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | static inline qsreal DayFromMonth(qsreal month, qsreal leap)
|
|---|
| 248 | {
|
|---|
| 249 | switch ((int) month) {
|
|---|
| 250 | case 0: return 0;
|
|---|
| 251 | case 1: return 31.0;
|
|---|
| 252 | case 2: return 59.0 + leap;
|
|---|
| 253 | case 3: return 90.0 + leap;
|
|---|
| 254 | case 4: return 120.0 + leap;
|
|---|
| 255 | case 5: return 151.0 + leap;
|
|---|
| 256 | case 6: return 181.0 + leap;
|
|---|
| 257 | case 7: return 212.0 + leap;
|
|---|
| 258 | case 8: return 243.0 + leap;
|
|---|
| 259 | case 9: return 273.0 + leap;
|
|---|
| 260 | case 10: return 304.0 + leap;
|
|---|
| 261 | case 11: return 334.0 + leap;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | return qSNaN(); // ### assert?
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | static qsreal MakeDay(qsreal year, qsreal month, qsreal day)
|
|---|
| 268 | {
|
|---|
| 269 | year += ::floor(month / 12.0);
|
|---|
| 270 |
|
|---|
| 271 | month = ::fmod(month, 12.0);
|
|---|
| 272 | if (month < 0)
|
|---|
| 273 | month += 12.0;
|
|---|
| 274 |
|
|---|
| 275 | qsreal t = TimeFromYear(year);
|
|---|
| 276 | qsreal leap = InLeapYear(t);
|
|---|
| 277 |
|
|---|
| 278 | day += ::floor(t / msPerDay);
|
|---|
| 279 | day += DayFromMonth(month, leap);
|
|---|
| 280 |
|
|---|
| 281 | return day - 1;
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | static inline qsreal MakeDate(qsreal day, qsreal time)
|
|---|
| 285 | {
|
|---|
| 286 | return day * msPerDay + time;
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | static inline qsreal DaylightSavingTA(double t)
|
|---|
| 290 | {
|
|---|
| 291 | #ifndef Q_WS_WIN
|
|---|
| 292 | long int tt = (long int)(t / msPerSecond);
|
|---|
| 293 | struct tm *tmtm = localtime((const time_t*)&tt);
|
|---|
| 294 | if (! tmtm)
|
|---|
| 295 | return 0;
|
|---|
| 296 | return (tmtm->tm_isdst > 0) ? msPerHour : 0;
|
|---|
| 297 | #else
|
|---|
| 298 | Q_UNUSED(t);
|
|---|
| 299 | /// ### implement me
|
|---|
| 300 | return 0;
|
|---|
| 301 | #endif
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | static inline qsreal LocalTime(qsreal t)
|
|---|
| 305 | {
|
|---|
| 306 | return t + LocalTZA + DaylightSavingTA(t);
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | static inline qsreal UTC(qsreal t)
|
|---|
| 310 | {
|
|---|
| 311 | return t - LocalTZA - DaylightSavingTA(t - LocalTZA);
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | static inline qsreal currentTime()
|
|---|
| 315 | {
|
|---|
| 316 | #ifndef Q_WS_WIN
|
|---|
| 317 | struct timeval tv;
|
|---|
| 318 |
|
|---|
| 319 | gettimeofday(&tv, 0);
|
|---|
| 320 | return ::floor(tv.tv_sec * msPerSecond + (tv.tv_usec / 1000.0));
|
|---|
| 321 | #else
|
|---|
| 322 | SYSTEMTIME st;
|
|---|
| 323 | GetSystemTime(&st);
|
|---|
| 324 | FILETIME ft;
|
|---|
| 325 | SystemTimeToFileTime(&st, &ft);
|
|---|
| 326 | LARGE_INTEGER li;
|
|---|
| 327 | li.LowPart = ft.dwLowDateTime;
|
|---|
| 328 | li.HighPart = ft.dwHighDateTime;
|
|---|
| 329 | return double(li.QuadPart - Q_INT64_C(116444736000000000)) / 10000.0;
|
|---|
| 330 | #endif
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | static inline qsreal TimeClip(qsreal t)
|
|---|
| 334 | {
|
|---|
| 335 | if (! qIsFinite(t) || fabs(t) > 8.64e15)
|
|---|
| 336 | return qSNaN();
|
|---|
| 337 | return QScriptEnginePrivate::toInteger(t);
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | static inline qsreal FromDateTime(const QDateTime &dt)
|
|---|
| 341 | {
|
|---|
| 342 | if (!dt.isValid())
|
|---|
| 343 | return qSNaN();
|
|---|
| 344 | QDate date = dt.date();
|
|---|
| 345 | QTime taim = dt.time();
|
|---|
| 346 | int year = date.year();
|
|---|
| 347 | int month = date.month() - 1;
|
|---|
| 348 | int day = date.day();
|
|---|
| 349 | int hours = taim.hour();
|
|---|
| 350 | int mins = taim.minute();
|
|---|
| 351 | int secs = taim.second();
|
|---|
| 352 | int ms = taim.msec();
|
|---|
| 353 | double t = MakeDate(MakeDay(year, month, day),
|
|---|
| 354 | MakeTime(hours, mins, secs, ms));
|
|---|
| 355 | if (dt.timeSpec() == Qt::LocalTime)
|
|---|
| 356 | t = UTC(t);
|
|---|
| 357 | return TimeClip(t);
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | static inline qsreal ParseString(const QString &s)
|
|---|
| 361 | {
|
|---|
| 362 | QDateTime dt = QDateTime::fromString(s, Qt::TextDate);
|
|---|
| 363 | if (!dt.isValid())
|
|---|
| 364 | dt = QDateTime::fromString(s, Qt::ISODate);
|
|---|
| 365 | if (!dt.isValid()) {
|
|---|
| 366 | QStringList formats;
|
|---|
| 367 | formats << QLatin1String("M/d/yyyy")
|
|---|
| 368 | << QLatin1String("M/d/yyyy hh:mm")
|
|---|
| 369 | << QLatin1String("M/d/yyyy hh:mm A")
|
|---|
| 370 |
|
|---|
| 371 | << QLatin1String("M/d/yyyy, hh:mm")
|
|---|
| 372 | << QLatin1String("M/d/yyyy, hh:mm A")
|
|---|
| 373 |
|
|---|
| 374 | << QLatin1String("MMM d yyyy")
|
|---|
| 375 | << QLatin1String("MMM d yyyy hh:mm")
|
|---|
| 376 | << QLatin1String("MMM d yyyy hh:mm:ss")
|
|---|
| 377 | << QLatin1String("MMM d yyyy, hh:mm")
|
|---|
| 378 | << QLatin1String("MMM d yyyy, hh:mm:ss")
|
|---|
| 379 |
|
|---|
| 380 | << QLatin1String("MMMM d yyyy")
|
|---|
| 381 | << QLatin1String("MMMM d yyyy hh:mm")
|
|---|
| 382 | << QLatin1String("MMMM d yyyy hh:mm:ss")
|
|---|
| 383 | << QLatin1String("MMMM d yyyy, hh:mm")
|
|---|
| 384 | << QLatin1String("MMMM d yyyy, hh:mm:ss")
|
|---|
| 385 |
|
|---|
| 386 | << QLatin1String("MMM d, yyyy")
|
|---|
| 387 | << QLatin1String("MMM d, yyyy hh:mm")
|
|---|
| 388 | << QLatin1String("MMM d, yyyy hh:mm:ss")
|
|---|
| 389 |
|
|---|
| 390 | << QLatin1String("MMMM d, yyyy")
|
|---|
| 391 | << QLatin1String("MMMM d, yyyy hh:mm")
|
|---|
| 392 | << QLatin1String("MMMM d, yyyy hh:mm:ss")
|
|---|
| 393 |
|
|---|
| 394 | << QLatin1String("d MMM yyyy")
|
|---|
| 395 | << QLatin1String("d MMM yyyy hh:mm")
|
|---|
| 396 | << QLatin1String("d MMM yyyy hh:mm:ss")
|
|---|
| 397 | << QLatin1String("d MMM yyyy, hh:mm")
|
|---|
| 398 | << QLatin1String("d MMM yyyy, hh:mm:ss")
|
|---|
| 399 |
|
|---|
| 400 | << QLatin1String("d MMMM yyyy")
|
|---|
| 401 | << QLatin1String("d MMMM yyyy hh:mm")
|
|---|
| 402 | << QLatin1String("d MMMM yyyy hh:mm:ss")
|
|---|
| 403 | << QLatin1String("d MMMM yyyy, hh:mm")
|
|---|
| 404 | << QLatin1String("d MMMM yyyy, hh:mm:ss")
|
|---|
| 405 |
|
|---|
| 406 | << QLatin1String("d MMM, yyyy")
|
|---|
| 407 | << QLatin1String("d MMM, yyyy hh:mm")
|
|---|
| 408 | << QLatin1String("d MMM, yyyy hh:mm:ss")
|
|---|
| 409 |
|
|---|
| 410 | << QLatin1String("d MMMM, yyyy")
|
|---|
| 411 | << QLatin1String("d MMMM, yyyy hh:mm")
|
|---|
| 412 | << QLatin1String("d MMMM, yyyy hh:mm:ss");
|
|---|
| 413 |
|
|---|
| 414 | for (int i = 0; i < formats.size(); ++i) {
|
|---|
| 415 | dt = QDateTime::fromString(s, formats.at(i));
|
|---|
| 416 | if (dt.isValid())
|
|---|
| 417 | break;
|
|---|
| 418 | }
|
|---|
| 419 | }
|
|---|
| 420 | return FromDateTime(dt);
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | /*!
|
|---|
| 424 | \internal
|
|---|
| 425 |
|
|---|
| 426 | Converts the ECMA Date value \tt (in UTC form) to QDateTime
|
|---|
| 427 | according to \a spec.
|
|---|
| 428 | */
|
|---|
| 429 | static inline QDateTime ToDateTime(qsreal t, Qt::TimeSpec spec)
|
|---|
| 430 | {
|
|---|
| 431 | if (qIsNaN(t))
|
|---|
| 432 | return QDateTime();
|
|---|
| 433 | if (spec == Qt::LocalTime)
|
|---|
| 434 | t = LocalTime(t);
|
|---|
| 435 | int year = int(YearFromTime(t));
|
|---|
| 436 | int month = int(MonthFromTime(t) + 1);
|
|---|
| 437 | int day = int(DateFromTime(t));
|
|---|
| 438 | int hours = HourFromTime(t);
|
|---|
| 439 | int mins = MinFromTime(t);
|
|---|
| 440 | int secs = SecFromTime(t);
|
|---|
| 441 | int ms = msFromTime(t);
|
|---|
| 442 | return QDateTime(QDate(year, month, day), QTime(hours, mins, secs, ms), spec);
|
|---|
| 443 | }
|
|---|
| 444 |
|
|---|
| 445 | static inline QString ToString(qsreal t)
|
|---|
| 446 | {
|
|---|
| 447 | if (qIsNaN(t))
|
|---|
| 448 | return QLatin1String("Invalid Date");
|
|---|
| 449 | QString str = ToDateTime(t, Qt::LocalTime).toString() + QLatin1String(" GMT");
|
|---|
| 450 | qsreal tzoffset = LocalTZA + DaylightSavingTA(t);
|
|---|
| 451 | if (tzoffset) {
|
|---|
| 452 | int hours = static_cast<int>(::fabs(tzoffset) / 1000 / 60 / 60);
|
|---|
| 453 | int mins = int(::fabs(tzoffset) / 1000 / 60) % 60;
|
|---|
| 454 | str.append(QLatin1Char((tzoffset > 0) ? '+' : '-'));
|
|---|
| 455 | if (hours < 10)
|
|---|
| 456 | str.append(QLatin1Char('0'));
|
|---|
| 457 | str.append(QString::number(hours));
|
|---|
| 458 | if (mins < 10)
|
|---|
| 459 | str.append(QLatin1Char('0'));
|
|---|
| 460 | str.append(QString::number(mins));
|
|---|
| 461 | }
|
|---|
| 462 | return str;
|
|---|
| 463 | }
|
|---|
| 464 |
|
|---|
| 465 | static inline QString ToUTCString(qsreal t)
|
|---|
| 466 | {
|
|---|
| 467 | if (qIsNaN(t))
|
|---|
| 468 | return QLatin1String("Invalid Date");
|
|---|
| 469 | return ToDateTime(t, Qt::UTC).toString() + QLatin1String(" GMT");
|
|---|
| 470 | }
|
|---|
| 471 |
|
|---|
| 472 | static inline QString ToDateString(qsreal t)
|
|---|
| 473 | {
|
|---|
| 474 | return ToDateTime(t, Qt::LocalTime).date().toString();
|
|---|
| 475 | }
|
|---|
| 476 |
|
|---|
| 477 | static inline QString ToTimeString(qsreal t)
|
|---|
| 478 | {
|
|---|
| 479 | return ToDateTime(t, Qt::LocalTime).time().toString();
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | static inline QString ToLocaleString(qsreal t)
|
|---|
| 483 | {
|
|---|
| 484 | return ToDateTime(t, Qt::LocalTime).toString(Qt::LocaleDate);
|
|---|
| 485 | }
|
|---|
| 486 |
|
|---|
| 487 | static inline QString ToLocaleDateString(qsreal t)
|
|---|
| 488 | {
|
|---|
| 489 | return ToDateTime(t, Qt::LocalTime).date().toString(Qt::LocaleDate);
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | static inline QString ToLocaleTimeString(qsreal t)
|
|---|
| 493 | {
|
|---|
| 494 | return ToDateTime(t, Qt::LocalTime).time().toString(Qt::LocaleDate);
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | static qsreal getLocalTZA()
|
|---|
| 498 | {
|
|---|
| 499 | #ifndef Q_WS_WIN
|
|---|
| 500 | struct tm* t;
|
|---|
| 501 | time_t curr;
|
|---|
| 502 | time(&curr);
|
|---|
| 503 | t = localtime(&curr);
|
|---|
| 504 | time_t locl = mktime(t);
|
|---|
| 505 | t = gmtime(&curr);
|
|---|
| 506 | time_t globl = mktime(t);
|
|---|
| 507 | return double(locl - globl) * 1000.0;
|
|---|
| 508 | #else
|
|---|
| 509 | TIME_ZONE_INFORMATION tzInfo;
|
|---|
| 510 | GetTimeZoneInformation(&tzInfo);
|
|---|
| 511 | return -tzInfo.Bias * 60.0 * 1000.0;
|
|---|
| 512 | #endif
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | namespace Ecma {
|
|---|
| 516 |
|
|---|
| 517 | Date::Date(QScriptEnginePrivate *eng):
|
|---|
| 518 | Core(eng, QLatin1String("Date"), QScriptClassInfo::DateType)
|
|---|
| 519 | {
|
|---|
| 520 | LocalTZA = getLocalTZA();
|
|---|
| 521 |
|
|---|
| 522 | newDate(&publicPrototype, qSNaN());
|
|---|
| 523 |
|
|---|
| 524 | eng->newConstructor(&ctor, this, publicPrototype);
|
|---|
| 525 | addConstructorFunction(QLatin1String("parse"), method_parse, 1);
|
|---|
| 526 | addConstructorFunction(QLatin1String("UTC"), method_UTC, 7);
|
|---|
| 527 |
|
|---|
| 528 | addPrototypeFunction(QLatin1String("toString"), method_toString, 0);
|
|---|
| 529 | addPrototypeFunction(QLatin1String("toDateString"), method_toDateString, 0);
|
|---|
| 530 | addPrototypeFunction(QLatin1String("toTimeString"), method_toTimeString, 0);
|
|---|
| 531 | addPrototypeFunction(QLatin1String("toLocaleString"), method_toLocaleString, 0);
|
|---|
| 532 | addPrototypeFunction(QLatin1String("toLocaleDateString"), method_toLocaleDateString, 0);
|
|---|
| 533 | addPrototypeFunction(QLatin1String("toLocaleTimeString"), method_toLocaleTimeString, 0);
|
|---|
| 534 | addPrototypeFunction(QLatin1String("valueOf"), method_valueOf, 0);
|
|---|
| 535 | addPrototypeFunction(QLatin1String("getTime"), method_getTime, 0);
|
|---|
| 536 | addPrototypeFunction(QLatin1String("getYear"), method_getYear, 0);
|
|---|
| 537 | addPrototypeFunction(QLatin1String("getFullYear"), method_getFullYear, 0);
|
|---|
| 538 | addPrototypeFunction(QLatin1String("getUTCFullYear"), method_getUTCFullYear, 0);
|
|---|
| 539 | addPrototypeFunction(QLatin1String("getMonth"), method_getMonth, 0);
|
|---|
| 540 | addPrototypeFunction(QLatin1String("getUTCMonth"), method_getUTCMonth, 0);
|
|---|
| 541 | addPrototypeFunction(QLatin1String("getDate"), method_getDate, 0);
|
|---|
| 542 | addPrototypeFunction(QLatin1String("getUTCDate"), method_getUTCDate, 0);
|
|---|
| 543 | addPrototypeFunction(QLatin1String("getDay"), method_getDay, 0);
|
|---|
| 544 | addPrototypeFunction(QLatin1String("getUTCDay"), method_getUTCDay, 0);
|
|---|
| 545 | addPrototypeFunction(QLatin1String("getHours"), method_getHours, 0);
|
|---|
| 546 | addPrototypeFunction(QLatin1String("getUTCHours"), method_getUTCHours, 0);
|
|---|
| 547 | addPrototypeFunction(QLatin1String("getMinutes"), method_getMinutes, 0);
|
|---|
| 548 | addPrototypeFunction(QLatin1String("getUTCMinutes"), method_getUTCMinutes, 0);
|
|---|
| 549 | addPrototypeFunction(QLatin1String("getSeconds"), method_getSeconds, 0);
|
|---|
| 550 | addPrototypeFunction(QLatin1String("getUTCSeconds"), method_getUTCSeconds, 0);
|
|---|
| 551 | addPrototypeFunction(QLatin1String("getMilliseconds"), method_getMilliseconds, 0);
|
|---|
| 552 | addPrototypeFunction(QLatin1String("getUTCMilliseconds"), method_getUTCMilliseconds, 0);
|
|---|
| 553 | addPrototypeFunction(QLatin1String("getTimezoneOffset"), method_getTimezoneOffset, 0);
|
|---|
| 554 | addPrototypeFunction(QLatin1String("setTime"), method_setTime, 1);
|
|---|
| 555 | addPrototypeFunction(QLatin1String("setMilliseconds"), method_setMilliseconds, 1);
|
|---|
| 556 | addPrototypeFunction(QLatin1String("setUTCMilliseconds"), method_setUTCMilliseconds, 1);
|
|---|
| 557 | addPrototypeFunction(QLatin1String("setSeconds"), method_setSeconds, 2);
|
|---|
| 558 | addPrototypeFunction(QLatin1String("setUTCSeconds"), method_setUTCSeconds, 2);
|
|---|
| 559 | addPrototypeFunction(QLatin1String("setMinutes"), method_setMinutes, 3);
|
|---|
| 560 | addPrototypeFunction(QLatin1String("setUTCMinutes"), method_setUTCMinutes, 3);
|
|---|
| 561 | addPrototypeFunction(QLatin1String("setHours"), method_setHours, 4);
|
|---|
| 562 | addPrototypeFunction(QLatin1String("setUTCHours"), method_setUTCHours, 4);
|
|---|
| 563 | addPrototypeFunction(QLatin1String("setDate"), method_setDate, 1);
|
|---|
| 564 | addPrototypeFunction(QLatin1String("setUTCDate"), method_setUTCDate, 1);
|
|---|
| 565 | addPrototypeFunction(QLatin1String("setMonth"), method_setMonth, 2);
|
|---|
| 566 | addPrototypeFunction(QLatin1String("setUTCMonth"), method_setUTCMonth, 2);
|
|---|
| 567 | addPrototypeFunction(QLatin1String("setYear"), method_setYear, 1);
|
|---|
| 568 | addPrototypeFunction(QLatin1String("setFullYear"), method_setFullYear, 3);
|
|---|
| 569 | addPrototypeFunction(QLatin1String("setUTCFullYear"), method_setUTCFullYear, 3);
|
|---|
| 570 | addPrototypeFunction(QLatin1String("toUTCString"), method_toUTCString, 0);
|
|---|
| 571 | addPrototypeFunction(QLatin1String("toGMTString"), method_toUTCString, 0);
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | Date::~Date()
|
|---|
| 575 | {
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | void Date::execute(QScriptContextPrivate *context)
|
|---|
| 579 | {
|
|---|
| 580 | #ifndef Q_SCRIPT_NO_EVENT_NOTIFY
|
|---|
| 581 | engine()->notifyFunctionEntry(context);
|
|---|
| 582 | #endif
|
|---|
| 583 | if (!context->isCalledAsConstructor()) {
|
|---|
| 584 | double t = currentTime();
|
|---|
| 585 | context->setReturnValue(QScriptValueImpl(engine(), ToString(t)));
|
|---|
| 586 | } else {
|
|---|
| 587 | // called as constructor
|
|---|
| 588 | qsreal t;
|
|---|
| 589 |
|
|---|
| 590 | if (context->argumentCount() == 0)
|
|---|
| 591 | t = currentTime();
|
|---|
| 592 |
|
|---|
| 593 | else if (context->argumentCount() == 1) {
|
|---|
| 594 | QScriptValueImpl arg = context->argument(0);
|
|---|
| 595 | if (arg.isDate())
|
|---|
| 596 | arg = arg.internalValue();
|
|---|
| 597 | else
|
|---|
| 598 | arg = engine()->toPrimitive(arg);
|
|---|
| 599 | if (arg.isString())
|
|---|
| 600 | t = ParseString(arg.toString());
|
|---|
| 601 | else
|
|---|
| 602 | t = TimeClip(arg.toNumber());
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | else { // context->argumentCount() > 1
|
|---|
| 606 | qsreal year = context->argument(0).toNumber();
|
|---|
| 607 | qsreal month = context->argument(1).toNumber();
|
|---|
| 608 | qsreal day = context->argumentCount() >= 3 ? context->argument(2).toNumber() : 1;
|
|---|
| 609 | qsreal hours = context->argumentCount() >= 4 ? context->argument(3).toNumber() : 0;
|
|---|
| 610 | qsreal mins = context->argumentCount() >= 5 ? context->argument(4).toNumber() : 0;
|
|---|
| 611 | qsreal secs = context->argumentCount() >= 6 ? context->argument(5).toNumber() : 0;
|
|---|
| 612 | qsreal ms = context->argumentCount() >= 7 ? context->argument(6).toNumber() : 0;
|
|---|
| 613 | if (year >= 0 && year <= 99)
|
|---|
| 614 | year += 1900;
|
|---|
| 615 | t = MakeDate(MakeDay(year, month, day), MakeTime(hours, mins, secs, ms));
|
|---|
| 616 | t = TimeClip(UTC(t));
|
|---|
| 617 | }
|
|---|
| 618 |
|
|---|
| 619 | QScriptValueImpl &obj = context->m_thisObject;
|
|---|
| 620 | obj.setClassInfo(classInfo());
|
|---|
| 621 | obj.setInternalValue(QScriptValueImpl(t));
|
|---|
| 622 | obj.setPrototype(publicPrototype);
|
|---|
| 623 | context->setReturnValue(obj);
|
|---|
| 624 | }
|
|---|
| 625 | #ifndef Q_SCRIPT_NO_EVENT_NOTIFY
|
|---|
| 626 | engine()->notifyFunctionExit(context);
|
|---|
| 627 | #endif
|
|---|
| 628 | }
|
|---|
| 629 |
|
|---|
| 630 | void Date::newDate(QScriptValueImpl *result, qsreal t)
|
|---|
| 631 | {
|
|---|
| 632 | engine()->newObject(result, publicPrototype, classInfo());
|
|---|
| 633 | result->setInternalValue(QScriptValueImpl(t));
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | void Date::newDate(QScriptValueImpl *result, const QDateTime &dt)
|
|---|
| 637 | {
|
|---|
| 638 | newDate(result, FromDateTime(dt));
|
|---|
| 639 | }
|
|---|
| 640 |
|
|---|
| 641 | void Date::newDate(QScriptValueImpl *result, const QDate &d)
|
|---|
| 642 | {
|
|---|
| 643 | newDate(result, QDateTime(d));
|
|---|
| 644 | }
|
|---|
| 645 |
|
|---|
| 646 | QDateTime Date::toDateTime(const QScriptValueImpl &date) const
|
|---|
| 647 | {
|
|---|
| 648 | Q_ASSERT(date.classInfo() == classInfo());
|
|---|
| 649 | qsreal t = date.internalValue().toNumber();
|
|---|
| 650 | return ToDateTime(t, Qt::LocalTime);
|
|---|
| 651 | }
|
|---|
| 652 |
|
|---|
| 653 | QScriptValueImpl Date::method_parse(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *)
|
|---|
| 654 | {
|
|---|
| 655 | return QScriptValueImpl(ParseString(context->argument(0).toString()));
|
|---|
| 656 | }
|
|---|
| 657 |
|
|---|
| 658 | QScriptValueImpl Date::method_UTC(QScriptContextPrivate *context, QScriptEnginePrivate *eng, QScriptClassInfo *)
|
|---|
| 659 | {
|
|---|
| 660 | const int numArgs = context->argumentCount();
|
|---|
| 661 | if (numArgs >= 2) {
|
|---|
| 662 | qsreal year = context->argument(0).toNumber();
|
|---|
| 663 | qsreal month = context->argument(1).toNumber();
|
|---|
| 664 | qsreal day = numArgs >= 3 ? context->argument(2).toNumber() : 1;
|
|---|
| 665 | qsreal hours = numArgs >= 4 ? context->argument(3).toNumber() : 0;
|
|---|
| 666 | qsreal mins = numArgs >= 5 ? context->argument(4).toNumber() : 0;
|
|---|
| 667 | qsreal secs = numArgs >= 6 ? context->argument(5).toNumber() : 0;
|
|---|
| 668 | qsreal ms = numArgs >= 7 ? context->argument(6).toNumber() : 0;
|
|---|
| 669 | if (year >= 0 && year <= 99)
|
|---|
| 670 | year += 1900;
|
|---|
| 671 | qsreal t = MakeDate(MakeDay(year, month, day),
|
|---|
| 672 | MakeTime(hours, mins, secs, ms));
|
|---|
| 673 | return QScriptValueImpl(TimeClip(t));
|
|---|
| 674 | }
|
|---|
| 675 | return (eng->undefinedValue());
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 | QScriptValueImpl Date::method_toString(QScriptContextPrivate *context, QScriptEnginePrivate *eng, QScriptClassInfo *classInfo)
|
|---|
| 679 | {
|
|---|
| 680 | QScriptValueImpl self = context->thisObject();
|
|---|
| 681 | if (self.classInfo() == classInfo) {
|
|---|
| 682 | qsreal t = self.internalValue().toNumber();
|
|---|
| 683 | return QScriptValueImpl(eng, ToString(t));
|
|---|
| 684 | }
|
|---|
| 685 | return throwThisObjectTypeError(
|
|---|
| 686 | context, QLatin1String("Date.prototype.toString"));
|
|---|
| 687 | }
|
|---|
| 688 |
|
|---|
| 689 | QScriptValueImpl Date::method_toDateString(QScriptContextPrivate *context, QScriptEnginePrivate *eng, QScriptClassInfo *classInfo)
|
|---|
| 690 | {
|
|---|
| 691 | QScriptValueImpl self = context->thisObject();
|
|---|
| 692 | if (self.classInfo() == classInfo) {
|
|---|
| 693 | qsreal t = self.internalValue().toNumber();
|
|---|
| 694 | return QScriptValueImpl(eng, ToDateString(t));
|
|---|
| 695 | }
|
|---|
| 696 | return throwThisObjectTypeError(
|
|---|
| 697 | context, QLatin1String("Date.prototype.toDateString"));
|
|---|
| 698 | }
|
|---|
| 699 |
|
|---|
| 700 | QScriptValueImpl Date::method_toTimeString(QScriptContextPrivate *context, QScriptEnginePrivate *eng, QScriptClassInfo *classInfo)
|
|---|
| 701 | {
|
|---|
| 702 | QScriptValueImpl self = context->thisObject();
|
|---|
| 703 | if (self.classInfo() == classInfo) {
|
|---|
| 704 | qsreal t = self.internalValue().toNumber();
|
|---|
| 705 | return QScriptValueImpl(eng, ToTimeString(t));
|
|---|
| 706 | }
|
|---|
| 707 | return throwThisObjectTypeError(
|
|---|
| 708 | context, QLatin1String("Date.prototype.toTimeString"));
|
|---|
| 709 | }
|
|---|
| 710 |
|
|---|
| 711 | QScriptValueImpl Date::method_toLocaleString(QScriptContextPrivate *context, QScriptEnginePrivate *eng, QScriptClassInfo *classInfo)
|
|---|
| 712 | {
|
|---|
| 713 | QScriptValueImpl self = context->thisObject();
|
|---|
| 714 | if (self.classInfo() == classInfo) {
|
|---|
| 715 | qsreal t = self.internalValue().toNumber();
|
|---|
| 716 | return QScriptValueImpl(eng, ToLocaleString(t));
|
|---|
| 717 | }
|
|---|
| 718 | return throwThisObjectTypeError(
|
|---|
| 719 | context, QLatin1String("Date.prototype.toLocaleString"));
|
|---|
| 720 | }
|
|---|
| 721 |
|
|---|
| 722 | QScriptValueImpl Date::method_toLocaleDateString(QScriptContextPrivate *context, QScriptEnginePrivate *eng, QScriptClassInfo *classInfo)
|
|---|
| 723 | {
|
|---|
| 724 | QScriptValueImpl self = context->thisObject();
|
|---|
| 725 | if (self.classInfo() == classInfo) {
|
|---|
| 726 | qsreal t = self.internalValue().toNumber();
|
|---|
| 727 | return QScriptValueImpl(eng, ToLocaleDateString(t));
|
|---|
| 728 | }
|
|---|
| 729 | return throwThisObjectTypeError(
|
|---|
| 730 | context, QLatin1String("Date.prototype.toLocaleDateString"));
|
|---|
| 731 | }
|
|---|
| 732 |
|
|---|
| 733 | QScriptValueImpl Date::method_toLocaleTimeString(QScriptContextPrivate *context, QScriptEnginePrivate *eng, QScriptClassInfo *classInfo)
|
|---|
| 734 | {
|
|---|
| 735 | QScriptValueImpl self = context->thisObject();
|
|---|
| 736 | if (self.classInfo() == classInfo) {
|
|---|
| 737 | qsreal t = self.internalValue().toNumber();
|
|---|
| 738 | return QScriptValueImpl(eng, ToLocaleTimeString(t));
|
|---|
| 739 | }
|
|---|
| 740 | return throwThisObjectTypeError(
|
|---|
| 741 | context, QLatin1String("Date.prototype.toLocaleTimeString"));
|
|---|
| 742 | }
|
|---|
| 743 |
|
|---|
| 744 | QScriptValueImpl Date::method_valueOf(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 745 | {
|
|---|
| 746 | QScriptValueImpl self = context->thisObject();
|
|---|
| 747 | if (self.classInfo() == classInfo)
|
|---|
| 748 | return QScriptValueImpl(self.internalValue().toNumber());
|
|---|
| 749 | return throwThisObjectTypeError(
|
|---|
| 750 | context, QLatin1String("Date.prototype.valueOf"));
|
|---|
| 751 | }
|
|---|
| 752 |
|
|---|
| 753 | QScriptValueImpl Date::method_getTime(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 754 | {
|
|---|
| 755 | QScriptValueImpl self = context->thisObject();
|
|---|
| 756 | if (self.classInfo() == classInfo)
|
|---|
| 757 | return QScriptValueImpl(self.internalValue().toNumber());
|
|---|
| 758 | return throwThisObjectTypeError(
|
|---|
| 759 | context, QLatin1String("Date.prototype.getTime"));
|
|---|
| 760 | }
|
|---|
| 761 |
|
|---|
| 762 | QScriptValueImpl Date::method_getYear(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 763 | {
|
|---|
| 764 | QScriptValueImpl self = context->thisObject();
|
|---|
| 765 | if (self.classInfo() == classInfo) {
|
|---|
| 766 | qsreal t = self.internalValue().toNumber();
|
|---|
| 767 | if (! qIsNaN(t))
|
|---|
| 768 | t = YearFromTime(LocalTime(t)) - 1900;
|
|---|
| 769 | return QScriptValueImpl(t);
|
|---|
| 770 | }
|
|---|
| 771 | return throwThisObjectTypeError(
|
|---|
| 772 | context, QLatin1String("Date.prototype.getYear"));
|
|---|
| 773 | }
|
|---|
| 774 |
|
|---|
| 775 | QScriptValueImpl Date::method_getFullYear(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 776 | {
|
|---|
| 777 | QScriptValueImpl self = context->thisObject();
|
|---|
| 778 | if (self.classInfo() == classInfo) {
|
|---|
| 779 | qsreal t = self.internalValue().toNumber();
|
|---|
| 780 | if (! qIsNaN(t))
|
|---|
| 781 | t = YearFromTime(LocalTime(t));
|
|---|
| 782 | return QScriptValueImpl(t);
|
|---|
| 783 | }
|
|---|
| 784 | return throwThisObjectTypeError(
|
|---|
| 785 | context, QLatin1String("Date.prototype.getFullYear"));
|
|---|
| 786 | }
|
|---|
| 787 |
|
|---|
| 788 | QScriptValueImpl Date::method_getUTCFullYear(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 789 | {
|
|---|
| 790 | QScriptValueImpl self = context->thisObject();
|
|---|
| 791 | if (self.classInfo() == classInfo) {
|
|---|
| 792 | qsreal t = self.internalValue().toNumber();
|
|---|
| 793 | if (! qIsNaN(t))
|
|---|
| 794 | t = YearFromTime(t);
|
|---|
| 795 | return QScriptValueImpl(t);
|
|---|
| 796 | }
|
|---|
| 797 | return throwThisObjectTypeError(
|
|---|
| 798 | context, QLatin1String("Date.prototype.getUTCFullYear"));
|
|---|
| 799 | }
|
|---|
| 800 |
|
|---|
| 801 | QScriptValueImpl Date::method_getMonth(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 802 | {
|
|---|
| 803 | QScriptValueImpl self = context->thisObject();
|
|---|
| 804 | if (self.classInfo() == classInfo) {
|
|---|
| 805 | qsreal t = self.internalValue().toNumber();
|
|---|
| 806 | if (! qIsNaN(t))
|
|---|
| 807 | t = MonthFromTime(LocalTime(t));
|
|---|
| 808 | return QScriptValueImpl(t);
|
|---|
| 809 | }
|
|---|
| 810 | return throwThisObjectTypeError(
|
|---|
| 811 | context, QLatin1String("Date.prototype.getMonth"));
|
|---|
| 812 | }
|
|---|
| 813 |
|
|---|
| 814 | QScriptValueImpl Date::method_getUTCMonth(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 815 | {
|
|---|
| 816 | QScriptValueImpl self = context->thisObject();
|
|---|
| 817 | if (self.classInfo() == classInfo) {
|
|---|
| 818 | qsreal t = self.internalValue().toNumber();
|
|---|
| 819 | if (! qIsNaN(t))
|
|---|
| 820 | t = MonthFromTime(t);
|
|---|
| 821 | return QScriptValueImpl(t);
|
|---|
| 822 | }
|
|---|
| 823 | return throwThisObjectTypeError(
|
|---|
| 824 | context, QLatin1String("Date.prototype.getUTCMonth"));
|
|---|
| 825 | }
|
|---|
| 826 |
|
|---|
| 827 | QScriptValueImpl Date::method_getDate(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 828 | {
|
|---|
| 829 | QScriptValueImpl self = context->thisObject();
|
|---|
| 830 | if (self.classInfo() == classInfo) {
|
|---|
| 831 | qsreal t = self.internalValue().toNumber();
|
|---|
| 832 | if (! qIsNaN(t))
|
|---|
| 833 | t = DateFromTime(LocalTime(t));
|
|---|
| 834 | return QScriptValueImpl(t);
|
|---|
| 835 | }
|
|---|
| 836 | return throwThisObjectTypeError(
|
|---|
| 837 | context, QLatin1String("Date.prototype.getDate"));
|
|---|
| 838 | }
|
|---|
| 839 |
|
|---|
| 840 | QScriptValueImpl Date::method_getUTCDate(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 841 | {
|
|---|
| 842 | QScriptValueImpl self = context->thisObject();
|
|---|
| 843 | if (self.classInfo() == classInfo) {
|
|---|
| 844 | qsreal t = self.internalValue().toNumber();
|
|---|
| 845 | if (! qIsNaN(t))
|
|---|
| 846 | t = DateFromTime(t);
|
|---|
| 847 | return QScriptValueImpl(t);
|
|---|
| 848 | }
|
|---|
| 849 | return throwThisObjectTypeError(
|
|---|
| 850 | context, QLatin1String("Date.prototype.getUTCDate"));
|
|---|
| 851 | }
|
|---|
| 852 |
|
|---|
| 853 | QScriptValueImpl Date::method_getDay(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 854 | {
|
|---|
| 855 | QScriptValueImpl self = context->thisObject();
|
|---|
| 856 | if (self.classInfo() == classInfo) {
|
|---|
| 857 | qsreal t = self.internalValue().toNumber();
|
|---|
| 858 | if (! qIsNaN(t))
|
|---|
| 859 | t = WeekDay(LocalTime(t));
|
|---|
| 860 | return QScriptValueImpl(t);
|
|---|
| 861 | }
|
|---|
| 862 | return throwThisObjectTypeError(
|
|---|
| 863 | context, QLatin1String("Date.prototype.getDay"));
|
|---|
| 864 | }
|
|---|
| 865 |
|
|---|
| 866 | QScriptValueImpl Date::method_getUTCDay(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 867 | {
|
|---|
| 868 | QScriptValueImpl self = context->thisObject();
|
|---|
| 869 | if (self.classInfo() == classInfo) {
|
|---|
| 870 | qsreal t = self.internalValue().toNumber();
|
|---|
| 871 | if (! qIsNaN(t))
|
|---|
| 872 | t = WeekDay(t);
|
|---|
| 873 | return QScriptValueImpl(t);
|
|---|
| 874 | }
|
|---|
| 875 | return throwThisObjectTypeError(
|
|---|
| 876 | context, QLatin1String("Date.prototype.getUTCDay"));
|
|---|
| 877 | }
|
|---|
| 878 |
|
|---|
| 879 | QScriptValueImpl Date::method_getHours(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 880 | {
|
|---|
| 881 | QScriptValueImpl self = context->thisObject();
|
|---|
| 882 | if (self.classInfo() == classInfo) {
|
|---|
| 883 | qsreal t = self.internalValue().toNumber();
|
|---|
| 884 | if (! qIsNaN(t))
|
|---|
| 885 | t = HourFromTime(LocalTime(t));
|
|---|
| 886 | return QScriptValueImpl(t);
|
|---|
| 887 | }
|
|---|
| 888 | return throwThisObjectTypeError(
|
|---|
| 889 | context, QLatin1String("Date.prototype.getHours"));
|
|---|
| 890 | }
|
|---|
| 891 |
|
|---|
| 892 | QScriptValueImpl Date::method_getUTCHours(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 893 | {
|
|---|
| 894 | QScriptValueImpl self = context->thisObject();
|
|---|
| 895 | if (self.classInfo() == classInfo) {
|
|---|
| 896 | qsreal t = self.internalValue().toNumber();
|
|---|
| 897 | if (! qIsNaN(t))
|
|---|
| 898 | t = HourFromTime(t);
|
|---|
| 899 | return QScriptValueImpl(t);
|
|---|
| 900 | }
|
|---|
| 901 | return throwThisObjectTypeError(
|
|---|
| 902 | context, QLatin1String("Date.prototype.getUTCHours"));
|
|---|
| 903 | }
|
|---|
| 904 |
|
|---|
| 905 | QScriptValueImpl Date::method_getMinutes(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 906 | {
|
|---|
| 907 | QScriptValueImpl self = context->thisObject();
|
|---|
| 908 | if (self.classInfo() == classInfo) {
|
|---|
| 909 | qsreal t = self.internalValue().toNumber();
|
|---|
| 910 | if (! qIsNaN(t))
|
|---|
| 911 | t = MinFromTime(LocalTime(t));
|
|---|
| 912 | return QScriptValueImpl(t);
|
|---|
| 913 | }
|
|---|
| 914 | return throwThisObjectTypeError(
|
|---|
| 915 | context, QLatin1String("Date.prototype.getMinutes"));
|
|---|
| 916 | }
|
|---|
| 917 |
|
|---|
| 918 | QScriptValueImpl Date::method_getUTCMinutes(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 919 | {
|
|---|
| 920 | QScriptValueImpl self = context->thisObject();
|
|---|
| 921 | if (self.classInfo() == classInfo) {
|
|---|
| 922 | qsreal t = self.internalValue().toNumber();
|
|---|
| 923 | if (! qIsNaN(t))
|
|---|
| 924 | t = MinFromTime(t);
|
|---|
| 925 | return QScriptValueImpl(t);
|
|---|
| 926 | }
|
|---|
| 927 | return throwThisObjectTypeError(
|
|---|
| 928 | context, QLatin1String("Date.prototype.getUTCMinutes"));
|
|---|
| 929 | }
|
|---|
| 930 |
|
|---|
| 931 | QScriptValueImpl Date::method_getSeconds(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 932 | {
|
|---|
| 933 | QScriptValueImpl self = context->thisObject();
|
|---|
| 934 | if (self.classInfo() == classInfo) {
|
|---|
| 935 | qsreal t = self.internalValue().toNumber();
|
|---|
| 936 | if (! qIsNaN(t))
|
|---|
| 937 | t = SecFromTime(LocalTime(t));
|
|---|
| 938 | return QScriptValueImpl(t);
|
|---|
| 939 | }
|
|---|
| 940 | return throwThisObjectTypeError(
|
|---|
| 941 | context, QLatin1String("Date.prototype.getSeconds"));
|
|---|
| 942 | }
|
|---|
| 943 |
|
|---|
| 944 | QScriptValueImpl Date::method_getUTCSeconds(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 945 | {
|
|---|
| 946 | QScriptValueImpl self = context->thisObject();
|
|---|
| 947 | if (self.classInfo() == classInfo) {
|
|---|
| 948 | qsreal t = self.internalValue().toNumber();
|
|---|
| 949 | if (! qIsNaN(t))
|
|---|
| 950 | t = SecFromTime(t);
|
|---|
| 951 | return QScriptValueImpl(t);
|
|---|
| 952 | }
|
|---|
| 953 | return throwThisObjectTypeError(
|
|---|
| 954 | context, QLatin1String("Date.prototype.getUTCSeconds"));
|
|---|
| 955 | }
|
|---|
| 956 |
|
|---|
| 957 | QScriptValueImpl Date::method_getMilliseconds(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 958 | {
|
|---|
| 959 | QScriptValueImpl self = context->thisObject();
|
|---|
| 960 | if (self.classInfo() == classInfo) {
|
|---|
| 961 | qsreal t = self.internalValue().toNumber();
|
|---|
| 962 | if (! qIsNaN(t))
|
|---|
| 963 | t = msFromTime(LocalTime(t));
|
|---|
| 964 | return QScriptValueImpl(t);
|
|---|
| 965 | }
|
|---|
| 966 | return throwThisObjectTypeError(
|
|---|
| 967 | context, QLatin1String("Date.prototype.getMilliseconds"));
|
|---|
| 968 | }
|
|---|
| 969 |
|
|---|
| 970 | QScriptValueImpl Date::method_getUTCMilliseconds(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 971 | {
|
|---|
| 972 | QScriptValueImpl self = context->thisObject();
|
|---|
| 973 | if (self.classInfo() == classInfo) {
|
|---|
| 974 | qsreal t = self.internalValue().toNumber();
|
|---|
| 975 | if (! qIsNaN(t))
|
|---|
| 976 | t = msFromTime(t);
|
|---|
| 977 | return QScriptValueImpl(t);
|
|---|
| 978 | }
|
|---|
| 979 | return throwThisObjectTypeError(
|
|---|
| 980 | context, QLatin1String("Date.prototype.getUTCMilliseconds"));
|
|---|
| 981 | }
|
|---|
| 982 |
|
|---|
| 983 | QScriptValueImpl Date::method_getTimezoneOffset(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 984 | {
|
|---|
| 985 | QScriptValueImpl self = context->thisObject();
|
|---|
| 986 | if (self.classInfo() == classInfo) {
|
|---|
| 987 | qsreal t = self.internalValue().toNumber();
|
|---|
| 988 | if (! qIsNaN(t))
|
|---|
| 989 | t = (t - LocalTime(t)) / msPerMinute;
|
|---|
| 990 | return QScriptValueImpl(t);
|
|---|
| 991 | }
|
|---|
| 992 | return throwThisObjectTypeError(
|
|---|
| 993 | context, QLatin1String("Date.prototype.getTimezoneOffset"));
|
|---|
| 994 | }
|
|---|
| 995 |
|
|---|
| 996 | QScriptValueImpl Date::method_setTime(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 997 | {
|
|---|
| 998 | QScriptValueImpl self = context->thisObject();
|
|---|
| 999 | if (self.classInfo() == classInfo) {
|
|---|
| 1000 | qsreal t = TimeClip(context->argument(0).toNumber());
|
|---|
| 1001 | QScriptValueImpl r(t);
|
|---|
| 1002 | self.setInternalValue(r);
|
|---|
| 1003 | return r;
|
|---|
| 1004 | }
|
|---|
| 1005 | return throwThisObjectTypeError(
|
|---|
| 1006 | context, QLatin1String("Date.prototype.setTime"));
|
|---|
| 1007 | }
|
|---|
| 1008 |
|
|---|
| 1009 | QScriptValueImpl Date::method_setMilliseconds(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1010 | {
|
|---|
| 1011 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1012 | if (self.classInfo() == classInfo) {
|
|---|
| 1013 | qsreal t = LocalTime(self.internalValue().toNumber());
|
|---|
| 1014 | qsreal ms = context->argument(0).toNumber();
|
|---|
| 1015 | t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms))));
|
|---|
| 1016 | QScriptValueImpl r(t);
|
|---|
| 1017 | self.setInternalValue(r);
|
|---|
| 1018 | return r;
|
|---|
| 1019 | }
|
|---|
| 1020 | return throwThisObjectTypeError(
|
|---|
| 1021 | context, QLatin1String("Date.prototype.setMilliseconds"));
|
|---|
| 1022 | }
|
|---|
| 1023 |
|
|---|
| 1024 | QScriptValueImpl Date::method_setUTCMilliseconds(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1025 | {
|
|---|
| 1026 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1027 | if (self.classInfo() == classInfo) {
|
|---|
| 1028 | qsreal t = self.internalValue().toNumber();
|
|---|
| 1029 | qsreal ms = context->argument(0).toNumber();
|
|---|
| 1030 | t = TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms)));
|
|---|
| 1031 | QScriptValueImpl r(t);
|
|---|
| 1032 | self.setInternalValue(r);
|
|---|
| 1033 | return r;
|
|---|
| 1034 | }
|
|---|
| 1035 | return throwThisObjectTypeError(
|
|---|
| 1036 | context, QLatin1String("Date.prototype.setUTCMilliseconds"));
|
|---|
| 1037 | }
|
|---|
| 1038 |
|
|---|
| 1039 | QScriptValueImpl Date::method_setSeconds(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1040 | {
|
|---|
| 1041 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1042 | if (self.classInfo() == classInfo) {
|
|---|
| 1043 | qsreal t = LocalTime(self.internalValue().toNumber());
|
|---|
| 1044 | qsreal sec = context->argument(0).toNumber();
|
|---|
| 1045 | qsreal ms = (context->argumentCount() < 2) ? msFromTime(t) : context->argument(1).toNumber();
|
|---|
| 1046 | t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), sec, ms))));
|
|---|
| 1047 | QScriptValueImpl r(t);
|
|---|
| 1048 | self.setInternalValue(r);
|
|---|
| 1049 | return r;
|
|---|
| 1050 | }
|
|---|
| 1051 | return throwThisObjectTypeError(
|
|---|
| 1052 | context, QLatin1String("Date.prototype.setSeconds"));
|
|---|
| 1053 | }
|
|---|
| 1054 |
|
|---|
| 1055 | QScriptValueImpl Date::method_setUTCSeconds(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1056 | {
|
|---|
| 1057 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1058 | if (self.classInfo() == classInfo) {
|
|---|
| 1059 | qsreal t = self.internalValue().toNumber();
|
|---|
| 1060 | qsreal sec = context->argument(0).toNumber();
|
|---|
| 1061 | qsreal ms = (context->argumentCount() < 2) ? msFromTime(t) : context->argument(1).toNumber();
|
|---|
| 1062 | t = TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), sec, ms)));
|
|---|
| 1063 | QScriptValueImpl r(t);
|
|---|
| 1064 | self.setInternalValue(r);
|
|---|
| 1065 | return r;
|
|---|
| 1066 | }
|
|---|
| 1067 | return throwThisObjectTypeError(
|
|---|
| 1068 | context, QLatin1String("Date.prototype.setUTCSeconds"));
|
|---|
| 1069 | }
|
|---|
| 1070 |
|
|---|
| 1071 | QScriptValueImpl Date::method_setMinutes(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1072 | {
|
|---|
| 1073 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1074 | if (self.classInfo() == classInfo) {
|
|---|
| 1075 | qsreal t = LocalTime(self.internalValue().toNumber());
|
|---|
| 1076 | qsreal min = context->argument(0).toNumber();
|
|---|
| 1077 | qsreal sec = (context->argumentCount() < 2) ? SecFromTime(t) : context->argument(1).toNumber();
|
|---|
| 1078 | qsreal ms = (context->argumentCount() < 3) ? msFromTime(t) : context->argument(2).toNumber();
|
|---|
| 1079 | t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), min, sec, ms))));
|
|---|
| 1080 | QScriptValueImpl r(t);
|
|---|
| 1081 | self.setInternalValue(r);
|
|---|
| 1082 | return r;
|
|---|
| 1083 | }
|
|---|
| 1084 | return throwThisObjectTypeError(
|
|---|
| 1085 | context, QLatin1String("Date.prototype.setMinutes"));
|
|---|
| 1086 | }
|
|---|
| 1087 |
|
|---|
| 1088 | QScriptValueImpl Date::method_setUTCMinutes(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1089 | {
|
|---|
| 1090 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1091 | if (self.classInfo() == classInfo) {
|
|---|
| 1092 | qsreal t = self.internalValue().toNumber();
|
|---|
| 1093 | qsreal min = context->argument(0).toNumber();
|
|---|
| 1094 | qsreal sec = (context->argumentCount() < 2) ? SecFromTime(t) : context->argument(1).toNumber();
|
|---|
| 1095 | qsreal ms = (context->argumentCount() < 3) ? msFromTime(t) : context->argument(2).toNumber();
|
|---|
| 1096 | t = TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), min, sec, ms)));
|
|---|
| 1097 | QScriptValueImpl r(t);
|
|---|
| 1098 | self.setInternalValue(r);
|
|---|
| 1099 | return r;
|
|---|
| 1100 | }
|
|---|
| 1101 | return throwThisObjectTypeError(
|
|---|
| 1102 | context, QLatin1String("Date.prototype.setUTCMinutes"));
|
|---|
| 1103 | }
|
|---|
| 1104 |
|
|---|
| 1105 | QScriptValueImpl Date::method_setHours(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1106 | {
|
|---|
| 1107 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1108 | if (self.classInfo() == classInfo) {
|
|---|
| 1109 | qsreal t = LocalTime(self.internalValue().toNumber());
|
|---|
| 1110 | qsreal hour = context->argument(0).toNumber();
|
|---|
| 1111 | qsreal min = (context->argumentCount() < 2) ? MinFromTime(t) : context->argument(1).toNumber();
|
|---|
| 1112 | qsreal sec = (context->argumentCount() < 3) ? SecFromTime(t) : context->argument(2).toNumber();
|
|---|
| 1113 | qsreal ms = (context->argumentCount() < 4) ? msFromTime(t) : context->argument(3).toNumber();
|
|---|
| 1114 | t = TimeClip(UTC(MakeDate(Day(t), MakeTime(hour, min, sec, ms))));
|
|---|
| 1115 | QScriptValueImpl r(t);
|
|---|
| 1116 | self.setInternalValue(r);
|
|---|
| 1117 | return r;
|
|---|
| 1118 | }
|
|---|
| 1119 | return throwThisObjectTypeError(
|
|---|
| 1120 | context, QLatin1String("Date.prototype.setHours"));
|
|---|
| 1121 | }
|
|---|
| 1122 |
|
|---|
| 1123 | QScriptValueImpl Date::method_setUTCHours(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1124 | {
|
|---|
| 1125 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1126 | if (self.classInfo() == classInfo) {
|
|---|
| 1127 | qsreal t = self.internalValue().toNumber();
|
|---|
| 1128 | qsreal hour = context->argument(0).toNumber();
|
|---|
| 1129 | qsreal min = (context->argumentCount() < 2) ? MinFromTime(t) : context->argument(1).toNumber();
|
|---|
| 1130 | qsreal sec = (context->argumentCount() < 3) ? SecFromTime(t) : context->argument(2).toNumber();
|
|---|
| 1131 | qsreal ms = (context->argumentCount() < 4) ? msFromTime(t) : context->argument(3).toNumber();
|
|---|
| 1132 | t = TimeClip(MakeDate(Day(t), MakeTime(hour, min, sec, ms)));
|
|---|
| 1133 | QScriptValueImpl r(t);
|
|---|
| 1134 | self.setInternalValue(r);
|
|---|
| 1135 | return r;
|
|---|
| 1136 | }
|
|---|
| 1137 | return throwThisObjectTypeError(
|
|---|
| 1138 | context, QLatin1String("Date.prototype.setUTCHours"));
|
|---|
| 1139 | }
|
|---|
| 1140 |
|
|---|
| 1141 | QScriptValueImpl Date::method_setDate(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1142 | {
|
|---|
| 1143 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1144 | if (self.classInfo() == classInfo) {
|
|---|
| 1145 | qsreal t = LocalTime(self.internalValue().toNumber());
|
|---|
| 1146 | qsreal date = context->argument(0).toNumber();
|
|---|
| 1147 | t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), date), TimeWithinDay(t))));
|
|---|
| 1148 | QScriptValueImpl r(t);
|
|---|
| 1149 | self.setInternalValue(r);
|
|---|
| 1150 | return r;
|
|---|
| 1151 | }
|
|---|
| 1152 | return throwThisObjectTypeError(
|
|---|
| 1153 | context, QLatin1String("Date.prototype.setDate"));
|
|---|
| 1154 | }
|
|---|
| 1155 |
|
|---|
| 1156 | QScriptValueImpl Date::method_setUTCDate(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1157 | {
|
|---|
| 1158 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1159 | if (self.classInfo() == classInfo) {
|
|---|
| 1160 | qsreal t = self.internalValue().toNumber();
|
|---|
| 1161 | qsreal date = context->argument(0).toNumber();
|
|---|
| 1162 | t = TimeClip(MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), date), TimeWithinDay(t)));
|
|---|
| 1163 | QScriptValueImpl r(t);
|
|---|
| 1164 | self.setInternalValue(r);
|
|---|
| 1165 | return r;
|
|---|
| 1166 | }
|
|---|
| 1167 | return throwThisObjectTypeError(
|
|---|
| 1168 | context, QLatin1String("Date.prototype.setUTCDate"));
|
|---|
| 1169 | }
|
|---|
| 1170 |
|
|---|
| 1171 | QScriptValueImpl Date::method_setMonth(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1172 | {
|
|---|
| 1173 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1174 | if (self.classInfo() == classInfo) {
|
|---|
| 1175 | qsreal t = LocalTime(self.internalValue().toNumber());
|
|---|
| 1176 | qsreal month = context->argument(0).toNumber();
|
|---|
| 1177 | qsreal date = (context->argumentCount() < 2) ? DateFromTime(t) : context->argument(1).toNumber();
|
|---|
| 1178 | t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), month, date), TimeWithinDay(t))));
|
|---|
| 1179 | QScriptValueImpl r(t);
|
|---|
| 1180 | self.setInternalValue(r);
|
|---|
| 1181 | return r;
|
|---|
| 1182 | }
|
|---|
| 1183 | return throwThisObjectTypeError(
|
|---|
| 1184 | context, QLatin1String("Date.prototype.setMonth"));
|
|---|
| 1185 | }
|
|---|
| 1186 |
|
|---|
| 1187 | QScriptValueImpl Date::method_setUTCMonth(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1188 | {
|
|---|
| 1189 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1190 | if (self.classInfo() == classInfo) {
|
|---|
| 1191 | qsreal t = self.internalValue().toNumber();
|
|---|
| 1192 | qsreal month = context->argument(0).toNumber();
|
|---|
| 1193 | qsreal date = (context->argumentCount() < 2) ? DateFromTime(t) : context->argument(1).toNumber();
|
|---|
| 1194 | t = TimeClip(MakeDate(MakeDay(YearFromTime(t), month, date), TimeWithinDay(t)));
|
|---|
| 1195 | QScriptValueImpl r(t);
|
|---|
| 1196 | self.setInternalValue(r);
|
|---|
| 1197 | return r;
|
|---|
| 1198 | }
|
|---|
| 1199 | return throwThisObjectTypeError(
|
|---|
| 1200 | context, QLatin1String("Date.prototype.setUTCMonth"));
|
|---|
| 1201 | }
|
|---|
| 1202 |
|
|---|
| 1203 | QScriptValueImpl Date::method_setFullYear(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1204 | {
|
|---|
| 1205 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1206 | if (self.classInfo() == classInfo) {
|
|---|
| 1207 | qsreal t = LocalTime(self.internalValue().toNumber());
|
|---|
| 1208 | qsreal year = context->argument(0).toNumber();
|
|---|
| 1209 | qsreal month = (context->argumentCount() < 2) ? MonthFromTime(t) : context->argument(1).toNumber();
|
|---|
| 1210 | qsreal date = (context->argumentCount() < 3) ? DateFromTime(t) : context->argument(2).toNumber();
|
|---|
| 1211 | t = TimeClip(UTC(MakeDate(MakeDay(year, month, date), TimeWithinDay(t))));
|
|---|
| 1212 | QScriptValueImpl r(t);
|
|---|
| 1213 | self.setInternalValue(r);
|
|---|
| 1214 | return r;
|
|---|
| 1215 | }
|
|---|
| 1216 | return throwThisObjectTypeError(
|
|---|
| 1217 | context, QLatin1String("Date.prototype.setFullYear"));
|
|---|
| 1218 | }
|
|---|
| 1219 |
|
|---|
| 1220 | QScriptValueImpl Date::method_setUTCFullYear(QScriptContextPrivate *context, QScriptEnginePrivate *, QScriptClassInfo *classInfo)
|
|---|
| 1221 | {
|
|---|
| 1222 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1223 | if (self.classInfo() == classInfo) {
|
|---|
| 1224 | qsreal t = self.internalValue().toNumber();
|
|---|
| 1225 | qsreal year = context->argument(0).toNumber();
|
|---|
| 1226 | qsreal month = (context->argumentCount() < 2) ? MonthFromTime(t) : context->argument(1).toNumber();
|
|---|
| 1227 | qsreal date = (context->argumentCount() < 3) ? DateFromTime(t) : context->argument(2).toNumber();
|
|---|
| 1228 | t = TimeClip(MakeDate(MakeDay(year, month, date), TimeWithinDay(t)));
|
|---|
| 1229 | QScriptValueImpl r(t);
|
|---|
| 1230 | self.setInternalValue(r);
|
|---|
| 1231 | return r;
|
|---|
| 1232 | }
|
|---|
| 1233 | return throwThisObjectTypeError(
|
|---|
| 1234 | context, QLatin1String("Date.prototype.setUTCFullYear"));
|
|---|
| 1235 | }
|
|---|
| 1236 |
|
|---|
| 1237 | QScriptValueImpl Date::method_setYear(QScriptContextPrivate *context, QScriptEnginePrivate *eng, QScriptClassInfo *classInfo)
|
|---|
| 1238 | {
|
|---|
| 1239 | Q_UNUSED(eng);
|
|---|
| 1240 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1241 | if (self.classInfo() == classInfo) {
|
|---|
| 1242 | qsreal t = self.internalValue().toNumber();
|
|---|
| 1243 | if (qIsNaN(t))
|
|---|
| 1244 | t = 0;
|
|---|
| 1245 | else
|
|---|
| 1246 | t = LocalTime(t);
|
|---|
| 1247 | qsreal year = context->argument(0).toNumber();
|
|---|
| 1248 | qsreal r;
|
|---|
| 1249 | if (qIsNaN(year)) {
|
|---|
| 1250 | r = qSNaN();
|
|---|
| 1251 | } else {
|
|---|
| 1252 | if ((eng->toInteger(year) >= 0) && (eng->toInteger(year) <= 99))
|
|---|
| 1253 | year += 1900;
|
|---|
| 1254 | r = MakeDay(year, MonthFromTime(t), DateFromTime(t));
|
|---|
| 1255 | r = UTC(MakeDate(r, TimeWithinDay(t)));
|
|---|
| 1256 | r = TimeClip(r);
|
|---|
| 1257 | }
|
|---|
| 1258 | QScriptValueImpl v = QScriptValueImpl(r);
|
|---|
| 1259 | self.setInternalValue(v);
|
|---|
| 1260 | return v;
|
|---|
| 1261 | }
|
|---|
| 1262 | return throwThisObjectTypeError(
|
|---|
| 1263 | context, QLatin1String("Date.prototype.setYear"));
|
|---|
| 1264 | }
|
|---|
| 1265 |
|
|---|
| 1266 | QScriptValueImpl Date::method_toUTCString(QScriptContextPrivate *context, QScriptEnginePrivate *eng, QScriptClassInfo *classInfo)
|
|---|
| 1267 | {
|
|---|
| 1268 | QScriptValueImpl self = context->thisObject();
|
|---|
| 1269 | if (self.classInfo() == classInfo) {
|
|---|
| 1270 | qsreal t = self.internalValue().toNumber();
|
|---|
| 1271 | return QScriptValueImpl(eng, ToUTCString(t));
|
|---|
| 1272 | }
|
|---|
| 1273 | return throwThisObjectTypeError(
|
|---|
| 1274 | context, QLatin1String("Date.prototype.toUTCString"));
|
|---|
| 1275 | }
|
|---|
| 1276 |
|
|---|
| 1277 | } } // namespace QScript::Ecma
|
|---|
| 1278 |
|
|---|
| 1279 | QT_END_NAMESPACE
|
|---|
| 1280 |
|
|---|
| 1281 | #endif // QT_NO_SCRIPT
|
|---|