本文整理汇总了C++中DateInstance类的典型用法代码示例。如果您正苦于以下问题:C++ DateInstance类的具体用法?C++ DateInstance怎么用?C++ DateInstance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dateProtoFuncGetUTCSeconds
EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCSeconds(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(DateInstance::info()))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec);
if (!gregorianDateTime)
return JSValue::encode(jsNaN());
return JSValue::encode(jsNumber(gregorianDateTime->second()));
}
示例2: dateProtoFuncGetDay
EncodedJSValue JSC_HOST_CALL dateProtoFuncGetDay(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(&DateInstance::info))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec);
if (!gregorianDateTime)
return JSValue::encode(jsNaN(exec));
return JSValue::encode(jsNumber(exec, gregorianDateTime->weekDay));
}
示例3: dateProtoFuncSetTime
EncodedJSValue JSC_HOST_CALL dateProtoFuncSetTime(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(DateInstance::info()))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
double milli = timeClip(exec->argument(0).toNumber(exec));
JSValue result = jsNumber(milli);
thisDateObj->setInternalValue(exec->vm(), result);
return JSValue::encode(result);
}
示例4: dateProtoFuncGetTimezoneOffset
EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTimezoneOffset(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(DateInstance::info()))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec);
if (!gregorianDateTime)
return JSValue::encode(jsNaN());
return JSValue::encode(jsNumber(-gregorianDateTime->utcOffset() / minutesPerHour));
}
示例5: dateProtoFuncGetUTCMilliseconds
JSValue JSC_HOST_CALL dateProtoFuncGetUTCMilliseconds(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
{
if (!thisValue.isObject(&DateInstance::info))
return throwError(exec, TypeError);
DateInstance* thisDateObj = asDateInstance(thisValue);
double milli = thisDateObj->internalNumber();
if (isnan(milli))
return jsNaN(exec);
double secs = floor(milli / msPerSecond);
double ms = milli - secs * msPerSecond;
return jsNumber(exec, ms);
}
示例6: dateProtoFuncToTimeString
EncodedJSValue JSC_HOST_CALL dateProtoFuncToTimeString(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(&DateInstance::s_info))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec);
if (!gregorianDateTime)
return JSValue::encode(jsNontrivialString(exec, "Invalid Date"));
DateConversionBuffer time;
formatTime(*gregorianDateTime, time);
return JSValue::encode(jsNontrivialString(exec, time));
}
示例7: dateProtoFuncGetYear
EncodedJSValue JSC_HOST_CALL dateProtoFuncGetYear(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
if (!thisValue.inherits(DateInstance::info()))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec);
if (!gregorianDateTime)
return JSValue::encode(jsNaN());
// NOTE: IE returns the full year even in getYear.
return JSValue::encode(jsNumber(gregorianDateTime->year() - 1900));
}
示例8: dateProtoFuncGetUTCMilliseconds
EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCMilliseconds(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
if (!thisValue.inherits(DateInstance::info()))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
double milli = thisDateObj->internalNumber();
if (std::isnan(milli))
return JSValue::encode(jsNaN());
double secs = floor(milli / msPerSecond);
double ms = milli - secs * msPerSecond;
return JSValue::encode(jsNumber(ms));
}
示例9: dateProtoFuncGetTimezoneOffset
JSValue JSC_HOST_CALL dateProtoFuncGetTimezoneOffset(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
{
if (!thisValue.isObject(&DateInstance::info))
return throwError(exec, TypeError);
const bool utc = false;
DateInstance* thisDateObj = asDateInstance(thisValue);
double milli = thisDateObj->internalNumber();
if (isnan(milli))
return jsNaN(exec);
GregorianDateTime t;
thisDateObj->msToGregorianDateTime(milli, utc, t);
return jsNumber(exec, -gmtoffset(t) / minutesPerHour);
}
示例10: dateProtoFuncGetUTCSeconds
JSValue JSC_HOST_CALL dateProtoFuncGetUTCSeconds(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
{
if (!thisValue.isObject(&DateInstance::info))
return throwError(exec, TypeError);
const bool utc = true;
DateInstance* thisDateObj = asDateInstance(thisValue);
double milli = thisDateObj->internalNumber();
if (isnan(milli))
return jsNaN(exec);
GregorianDateTime t;
thisDateObj->msToGregorianDateTime(milli, utc, t);
return jsNumber(exec, t.second);
}
示例11: dateProtoFuncToGMTString
JSValue JSC_HOST_CALL dateProtoFuncToGMTString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
{
if (!thisValue.isObject(&DateInstance::info))
return throwError(exec, TypeError);
const bool utc = true;
DateInstance* thisDateObj = asDateInstance(thisValue);
double milli = thisDateObj->internalNumber();
if (isnan(milli))
return jsNontrivialString(exec, "Invalid Date");
GregorianDateTime t;
thisDateObj->msToGregorianDateTime(milli, utc, t);
return jsNontrivialString(exec, formatDateUTCVariant(t) + " " + formatTime(t, utc));
}
示例12: formateDateInstance
static EncodedJSValue formateDateInstance(ExecState* exec, DateTimeFormat format, bool asUTCVariant)
{
JSValue thisValue = exec->thisValue();
if (!thisValue.inherits(DateInstance::info()))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
const GregorianDateTime* gregorianDateTime = asUTCVariant
? thisDateObj->gregorianDateTimeUTC(exec)
: thisDateObj->gregorianDateTime(exec);
if (!gregorianDateTime)
return JSValue::encode(jsNontrivialString(exec, String(ASCIILiteral("Invalid Date"))));
return JSValue::encode(jsNontrivialString(exec, formatDateTime(*gregorianDateTime, format, asUTCVariant)));
}
示例13: constructDate
// ECMA 15.9.3
JSObject* constructDate(ExecState* exec, const ArgList& args)
{
int numArgs = args.size();
double value;
if (numArgs == 0) // new Date() ECMA 15.9.3.3
value = getCurrentUTCTime();
else if (numArgs == 1) {
if (args.at(exec, 0)->isObject(&DateInstance::info))
value = asDateInstance(args.at(exec, 0))->internalNumber();
else {
JSValue* primitive = args.at(exec, 0)->toPrimitive(exec);
if (primitive->isString())
value = parseDate(primitive->getString());
else
value = primitive->toNumber(exec);
}
} else {
if (isnan(args.at(exec, 0)->toNumber(exec))
|| isnan(args.at(exec, 1)->toNumber(exec))
|| (numArgs >= 3 && isnan(args.at(exec, 2)->toNumber(exec)))
|| (numArgs >= 4 && isnan(args.at(exec, 3)->toNumber(exec)))
|| (numArgs >= 5 && isnan(args.at(exec, 4)->toNumber(exec)))
|| (numArgs >= 6 && isnan(args.at(exec, 5)->toNumber(exec)))
|| (numArgs >= 7 && isnan(args.at(exec, 6)->toNumber(exec))))
value = NaN;
else {
GregorianDateTime t;
int year = args.at(exec, 0)->toInt32(exec);
t.year = (year >= 0 && year <= 99) ? year : year - 1900;
t.month = args.at(exec, 1)->toInt32(exec);
t.monthDay = (numArgs >= 3) ? args.at(exec, 2)->toInt32(exec) : 1;
t.hour = args.at(exec, 3)->toInt32(exec);
t.minute = args.at(exec, 4)->toInt32(exec);
t.second = args.at(exec, 5)->toInt32(exec);
t.isDST = -1;
double ms = (numArgs >= 7) ? args.at(exec, 6)->toNumber(exec) : 0;
value = gregorianDateTimeToMS(t, ms, false);
}
}
DateInstance* result = new (exec) DateInstance(exec->lexicalGlobalObject()->dateStructure());
result->setInternalValue(jsNumber(exec, timeClip(value)));
return result;
}
示例14: dateProtoFuncGetYear
JSValue JSC_HOST_CALL dateProtoFuncGetYear(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
{
if (!thisValue.isObject(&DateInstance::info))
return throwError(exec, TypeError);
const bool utc = false;
DateInstance* thisDateObj = asDateInstance(thisValue);
double milli = thisDateObj->internalNumber();
if (isnan(milli))
return jsNaN(exec);
GregorianDateTime t;
thisDateObj->msToGregorianDateTime(milli, utc, t);
// NOTE: IE returns the full year even in getYear.
return jsNumber(exec, t.year);
}
示例15: dateProtoFuncToISOString
EncodedJSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(&DateInstance::s_info))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec);
if (!gregorianDateTime)
return JSValue::encode(jsNontrivialString(exec, "Invalid Date"));
// Maximum amount of space we need in buffer: 6 (max. digits in year) + 2 * 5 (2 characters each for month, day, hour, minute, second) + 4 (. + 3 digits for milliseconds)
// 6 for formatting and one for null termination = 27. We add one extra character to allow us to force null termination.
char buffer[28];
snprintf(buffer, sizeof(buffer) - 1, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + gregorianDateTime->year, gregorianDateTime->month + 1, gregorianDateTime->monthDay, gregorianDateTime->hour, gregorianDateTime->minute, gregorianDateTime->second, static_cast<int>(fmod(thisDateObj->internalNumber(), 1000)));
buffer[sizeof(buffer) - 1] = 0;
return JSValue::encode(jsNontrivialString(exec, buffer));
}