bool JS4D::DateObjectToVTime( ContextRef inContext, ObjectRef inObject, VTime& outTime, ExceptionRef *outException) { // it's caller responsibility to check inObject is really a Date using ValueIsInstanceOf // call getTime() bool ok = false; JSStringRef jsString = JSStringCreateWithUTF8CString( "getTime"); JSValueRef getTime = JSObjectGetProperty( inContext, inObject, jsString, outException); JSObjectRef getTimeFunction = JSValueToObject( inContext, getTime, outException); JSStringRelease( jsString); JSValueRef result = (getTime != NULL) ? JSObjectCallAsFunction( inContext, getTimeFunction, inObject, 0, NULL, outException) : NULL; if (result != NULL) { // The getTime() method returns the number of milliseconds since midnight of January 1, 1970. double r = JSValueToNumber( inContext, result, outException); sLONG8 n = (sLONG8) r; if (n == r) { outTime.FromUTCTime( 1970, 1, 1, 0, 0, 0, 0); outTime.AddMilliseconds( n); ok = true; } else { outTime.SetNull( true); } } else { outTime.SetNull( true); } return ok; }
void VJSONValue::GetTime(VTime& outTime) const { VError err = VE_OK; switch (fType) { case JSON_string: { VString s; s.FromString(fString); outTime.FromString(s); break; } case JSON_date: { outTime.FromMilliseconds(fTimeStamp); break; } case JSON_number: { outTime.FromMilliseconds(fNumber); break; } default: { outTime.Clear(); outTime.SetNull(true); break; } } }
bool VJSValue::GetTime( VTime& outTime, JS4D::ExceptionRef *outException) const { bool ok; if (JS4D::ValueIsInstanceOf( fContext, fValue, CVSTR( "Date"), outException)) { JSObjectRef dateObject = JSValueToObject( fContext, fValue, outException); ok = JS4D::DateObjectToVTime( fContext, dateObject, outTime, outException, false); } else { outTime.SetNull( true); ok = false; } return ok; }