本文整理汇总了C++中DateInstance::gregorianDateTime方法的典型用法代码示例。如果您正苦于以下问题:C++ DateInstance::gregorianDateTime方法的具体用法?C++ DateInstance::gregorianDateTime怎么用?C++ DateInstance::gregorianDateTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateInstance
的用法示例。
在下文中一共展示了DateInstance::gregorianDateTime方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dateProtoFuncGetSeconds
EncodedJSValue JSC_HOST_CALL dateProtoFuncGetSeconds(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());
return JSValue::encode(jsNumber(gregorianDateTime->second()));
}
示例2: dateProtoFuncGetTimezoneOffset
EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTimezoneOffset(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());
return JSValue::encode(jsNumber(-gregorianDateTime->utcOffset() / minutesPerHour));
}
示例3: dateProtoFuncGetFullYear
EncodedJSValue JSC_HOST_CALL dateProtoFuncGetFullYear(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(jsNaN());
return JSValue::encode(jsNumber(1900 + gregorianDateTime->year));
}
示例4: 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));
}
示例5: 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));
}
示例6: 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)));
}
示例7: dateProtoFuncSetYear
EncodedJSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
if (!thisValue.inherits(DateInstance::info()))
return throwVMTypeError(exec);
VM& vm = exec->vm();
DateInstance* thisDateObj = asDateInstance(thisValue);
if (!exec->argumentCount()) {
JSValue result = jsNaN();
thisDateObj->setInternalValue(vm, result);
return JSValue::encode(result);
}
double milli = thisDateObj->internalNumber();
double ms = 0;
GregorianDateTime gregorianDateTime;
if (std::isnan(milli))
// Based on ECMA 262 B.2.5 (setYear)
// the time must be reset to +0 if it is NaN.
msToGregorianDateTime(vm, 0, true, gregorianDateTime);
else {
double secs = floor(milli / msPerSecond);
ms = milli - secs * msPerSecond;
if (const GregorianDateTime* other = thisDateObj->gregorianDateTime(exec))
gregorianDateTime.copyFrom(*other);
}
double year = exec->argument(0).toIntegerPreserveNaN(exec);
if (!std::isfinite(year)) {
JSValue result = jsNaN();
thisDateObj->setInternalValue(vm, result);
return JSValue::encode(result);
}
gregorianDateTime.setYear(toInt32((year >= 0 && year <= 99) ? (year + 1900) : year));
JSValue result = jsNumber(gregorianDateTimeToMS(vm, gregorianDateTime, ms, false));
thisDateObj->setInternalValue(vm, result);
return JSValue::encode(result);
}
示例8: dateProtoFuncSetYear
EncodedJSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(&DateInstance::info))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
if (!exec->argumentCount()) {
JSValue result = jsNaN(exec);
thisDateObj->setInternalValue(result);
return JSValue::encode(result);
}
double milli = thisDateObj->internalNumber();
double ms = 0;
GregorianDateTime gregorianDateTime;
if (isnan(milli))
// Based on ECMA 262 B.2.5 (setYear)
// the time must be reset to +0 if it is NaN.
msToGregorianDateTime(exec, 0, true, gregorianDateTime);
else {
double secs = floor(milli / msPerSecond);
ms = milli - secs * msPerSecond;
if (const GregorianDateTime* other = thisDateObj->gregorianDateTime(exec))
gregorianDateTime.copyFrom(*other);
}
bool ok = true;
int32_t year = exec->argument(0).toInt32(exec, ok);
if (!ok) {
JSValue result = jsNaN(exec);
thisDateObj->setInternalValue(result);
return JSValue::encode(result);
}
gregorianDateTime.year = (year > 99 || year < 0) ? year - 1900 : year;
JSValue result = jsNumber(exec, gregorianDateTimeToMS(exec, gregorianDateTime, ms, false));
thisDateObj->setInternalValue(result);
return JSValue::encode(result);
}
示例9: setNewValueFromDateArgs
static EncodedJSValue setNewValueFromDateArgs(ExecState* exec, int numArgsToUse, bool inputIsUTC)
{
JSValue thisValue = exec->thisValue();
if (!thisValue.inherits(DateInstance::info()))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
if (!exec->argumentCount()) {
JSValue result = jsNaN();
thisDateObj->setInternalValue(exec->vm(), result);
return JSValue::encode(result);
}
VM& vm = exec->vm();
double milli = thisDateObj->internalNumber();
double ms = 0;
GregorianDateTime gregorianDateTime;
if (numArgsToUse == 3 && std::isnan(milli))
msToGregorianDateTime(vm, 0, true, gregorianDateTime);
else {
ms = milli - floor(milli / msPerSecond) * msPerSecond;
const GregorianDateTime* other = inputIsUTC
? thisDateObj->gregorianDateTimeUTC(exec)
: thisDateObj->gregorianDateTime(exec);
if (!other)
return JSValue::encode(jsNaN());
gregorianDateTime.copyFrom(*other);
}
if (!fillStructuresUsingDateArgs(exec, numArgsToUse, &ms, &gregorianDateTime)) {
JSValue result = jsNaN();
thisDateObj->setInternalValue(vm, result);
return JSValue::encode(result);
}
JSValue result = jsNumber(gregorianDateTimeToMS(vm, gregorianDateTime, ms, inputIsUTC));
thisDateObj->setInternalValue(vm, result);
return JSValue::encode(result);
}
示例10: setNewValueFromTimeArgs
static EncodedJSValue setNewValueFromTimeArgs(ExecState* exec, int numArgsToUse, bool inputIsUTC)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(&DateInstance::s_info))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
double milli = thisDateObj->internalNumber();
if (!exec->argumentCount() || isnan(milli)) {
JSValue result = jsNaN();
thisDateObj->setInternalValue(exec->globalData(), result);
return JSValue::encode(result);
}
double secs = floor(milli / msPerSecond);
double ms = milli - secs * msPerSecond;
const GregorianDateTime* other = inputIsUTC
? thisDateObj->gregorianDateTimeUTC(exec)
: thisDateObj->gregorianDateTime(exec);
if (!other)
return JSValue::encode(jsNaN());
GregorianDateTime gregorianDateTime;
gregorianDateTime.copyFrom(*other);
if (!fillStructuresUsingTimeArgs(exec, numArgsToUse, &ms, &gregorianDateTime)) {
JSValue result = jsNaN();
thisDateObj->setInternalValue(exec->globalData(), result);
return JSValue::encode(result);
}
JSValue result = jsNumber(gregorianDateTimeToMS(exec, gregorianDateTime, ms, inputIsUTC));
thisDateObj->setInternalValue(exec->globalData(), result);
return JSValue::encode(result);
}