MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / evlDateDiff

Function evlDateDiff

src/jrd/SysFunction.cpp:4051–4279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4049
4050
4051dsc* evlDateDiff(thread_db* tdbb, const SysFunction* function, const NestValueArray& args,
4052 impure_value* impure)
4053{
4054 fb_assert(args.getCount() == 3);
4055
4056 Request* request = tdbb->getRequest();
4057
4058 const dsc* partDsc = EVL_expr(tdbb, request, args[0]);
4059 if (request->req_flags & req_null) // return NULL if partDsc is NULL
4060 return NULL;
4061
4062 const dsc* value1Dsc = EVL_expr(tdbb, request, args[1]);
4063 if (request->req_flags & req_null) // return NULL if value1Dsc is NULL
4064 return NULL;
4065
4066 const dsc* value2Dsc = EVL_expr(tdbb, request, args[2]);
4067 if (request->req_flags & req_null) // return NULL if value2Dsc is NULL
4068 return NULL;
4069
4070 TimeStamp timestamp1;
4071
4072 switch (value1Dsc->dsc_dtype)
4073 {
4074 case dtype_sql_time:
4075 case dtype_sql_time_tz:
4076 timestamp1.value().timestamp_time = *(GDS_TIME*) value1Dsc->dsc_address;
4077 timestamp1.value().timestamp_date = 0;
4078
4079 if (value1Dsc->dsc_dtype == dtype_sql_time && value2Dsc->isDateTimeTz())
4080 {
4081 TimeZoneUtil::localTimeToUtc(timestamp1.value().timestamp_time,
4082 EngineCallbacks::instance->getSessionTimeZone());
4083 }
4084 break;
4085
4086 case dtype_sql_date:
4087 timestamp1.value().timestamp_date = *(GDS_DATE*) value1Dsc->dsc_address;
4088 timestamp1.value().timestamp_time = 0;
4089 break;
4090
4091 case dtype_timestamp:
4092 case dtype_timestamp_tz:
4093 timestamp1.value() = *(GDS_TIMESTAMP*) value1Dsc->dsc_address;
4094
4095 if (value1Dsc->dsc_dtype == dtype_timestamp && value2Dsc->isDateTimeTz())
4096 TimeZoneUtil::localTimeStampToUtc(timestamp1.value(), &EngineCallbacks::instance);
4097 break;
4098
4099 default:
4100 status_exception::raise(Arg::Gds(isc_expression_eval_err) <<
4101 Arg::Gds(isc_sysf_invalid_diff_dtime) <<
4102 Arg::Str(function->name));
4103 break;
4104 }
4105
4106 TimeStamp timestamp2;
4107
4108 switch (value2Dsc->dsc_dtype)

Callers

nothing calls this directly

Calls 15

EVL_exprFunction · 0.85
raiseFunction · 0.85
GdsClass · 0.85
StrClass · 0.85
MOV_get_longFunction · 0.85
getPartNameFunction · 0.85
isDateTimeTzMethod · 0.80
isTimeMethod · 0.80
isTimeStampMethod · 0.80
makeInt64Method · 0.80
getCountMethod · 0.45
getRequestMethod · 0.45

Tested by

no test coverage detected