function DateTimeToUnix how to use it? - delphi

could you guys give a an example of a code that prints DateTimeToUnix in Pascal?
Found out a topic talking about in Delphi (DateTimeToUnix in UTC?), but i cant find a code example anywhere.
function DateTimeToUnix(
const AValue: TDateTime
):Int64;
Here is an example in c#
public static int UnixTimeStamp()
{
return (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
}
}
Also, i did a little search and this function seems to print the System time without using timezone (UTC), so how i could adjust the result to the timezone i want (eg. UTC -3).
Thanks,

Related

Prestashop convertPrice doesn't convert price

Using Prestashop 1.6.1.4
The theme function
{convertPrice price=$total}
Add the current currency sign but doesn't actually convert the to the chosen currency.
I followed the debugger to function (classes/Product.php, line 3034):
public static function convertPrice($params, &$smarty)
{
return Tools::displayPrice($params['price'], Context::getContext()->currency);
}
Which is strange since the convertPrice eventually calls displayPrice while Tools::convertPrice(...) is the function that convert the currency (but doesn't add the currency sign).
So I change it to :
return Tools::displayConvertPrice($params['price'], Context::getContext()->currency);
and added to Tools.php
public function displayConvertPrice($price, $currency)
{
return Tools::displayPrice(Tools::convertPrice($price, $currency), $currency);
}
My question:
Is it a bug or that I'm missing something?
Who knows what the devs wanted with that but there is a smarty function
{convertAndFormatPrice price=$total}
which does what you want.
You can open /config/smarty.config.inc.php and you'll see all prestashop functions registered in smarty smartyRegisterFunction(yada yada).
Use
{toolsConvertPrice price=$total}
this works for me on PS 1.6.1.12.

Report Code (.frf file)

in the below code I would like to change the final IF NOT statement to say either HEADING or SPACE. I have tried to play around with it (I did not write this code) without success. Sorry am not an expert not sure what code it is in! Any ideas? Thanks
if [POS('HEADING',[DF.Items."CODE"])] then MemoLRV.visible:=false;
if [POS('SPACE',[DF.Items."CODE"])] then MemoLRV.visible:=false;
if [POS('HEADING',[DF.Items."CODE"])] then MemonameV.font.Color:=clmaroon;
if not [POS('HEADING',[DF.Items."CODE"])] then MemonameV.font.Color:=clblack;
if not [POS('HEADING',[DF.Items."CODE"])] then MemoLRV.visible:=true;
In FastReport function IF :
IF(Expression, Value1, Value2)
Returns Value1 if expression Expression is True, otherwise returns Value2. Return value can be not only string.

LoadRunner web_reg_save_param, ord=all, paramName_count issues

I am using LoadRunner version 12.02 - Build 2739
Looking at an old, yet correct 'guide' shows that I have used the statements correctly (3rd Point, around 1/3rd of the way down the page, inside the code block - the atoi statement).
But I am still unable to convert the _count parameter to an int-Variable.
In the script, before the call is made;
web_reg_save_param(
"ParamName=rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
After the web call the save_param function is placed before, the output log shows;
Notify: Saving Parameter "ParamName=rotaPeople_count = 21".
Inside the script, after the call is made, and the count has been totaled;
lr_output_message("RP_C:%d",lr_eval_string("{rotaPeople_count}"));
lr_output_message("RP_C:%s",lr_eval_string("{rotaPeople_count}"));
peoplesCount = atoi(lr_eval_string("{rotaPeople_count}"));
lr_output_message("PC:%d",peoplesCount);
In the logs after the above executions are made;
Warning: The string 'rotaPeople_count' with parameter delimiters is not a parameter.
RP_C:110826864
Warning: The string 'rotaPeople_count' with parameter delimiters is not a parameter.
RP_C:{rotaPeople_count}
Warning: The string 'rotaPeople_count' with parameter delimiters is not a parameter.
PC:0
Anyone have any ideas?
Note: The Warning messages are expected
Note: Workaround: Used web_reg_save_param_regex() and created a regular expression. Using the returned _count parameter within a for-loop worked. Keeping question open, as the original problem still persists
The problem is that you use a soon to be deprecated API web_reg_save_param which does not support the ParamName syntax. In this API the second parameter is always the parameter name and therefore the correct use would be:
web_reg_save_param(
"rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
The proper API to use is web_reg_save_param_ex which does support the syntax you used so the call should look like:
web_reg_save_param_ex(
"ParamName=rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
Then the rest of your code should work properly.
I am not sure what you are doing but you might want to take a look at the somewhat unknown API lr_paramarr_random which will automatically pull a random value from the parameters array.
This should help you
web_reg_save_param(
"rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
lr_output_message("PC:%d",atoi(lr_eval_string("{rotaPeople_count}")));
You are using ord=all,see the run time data which value you want to capture,If you want to capture the 10th value please use ord=10,automatically this warning will remove from output log.
Example for capturing an array of dynamic values:
Action()
{
int i;
int ncount;
char ParamName[100];
web_set_sockets_option("SSL_VERSION", "TLS");
web_reg_save_param("trackingno","LB=;","RB= (NTN 0430)","search=All","ord=all",LAST);
web_submit_data("barcode.pl",
"Action=http://qtetools.rmtc.fedex.com/barcode/cgi-bin/barcode.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://qtetools.rmtc.fedex.com/barcode/html/barcode.shtml",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=formcode", "Value=0430", ENDITEM,
"Name=count", "Value=10", ENDITEM,
"Name=narrow", "Value=2", ENDITEM,
LAST);
ncount= atoi(lr_eval_string("{trackingno_count}"));
for (i =1;i <= ncount;i++)
{
sprintf(ParamName, "{trackingno_%d}", i);
lr_output_message("Value of %s: %s",ParamName,lr_eval_string(ParamName));
}
return 0;
}

(delphi application) wrong location spotted

i have pairs of coorinates:
GpsLatitude GpsLongitude
32.012919 34.547592,
32.012798 34.54763,
32.012827 34.547584,
32.012814 34.547608,
32.01273 34.54765,
32.012868 34.547631,
32.012834 34.547577,
and i have show it on google map in delphi application.
i find an example here a delphi code example
and it works. But when i trying to use it with my coordinates it point
to wrong location, but when i open it in browser, like this
"32 01.2834,34 54.7577"
it work good, unfortunatly it does not work in delphi.
what can be wrong??
if you look the GotoLatLng javascript function used in the article,
function GotoLatLng(Lat, Lang) {
var latlng = new google.maps.LatLng(Lat,Lang);
map.setCenter(latlng);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title:Lat+","+Lang
});
}
You can see a call to the google.maps.LatLng() function, and this needs to be given two numbers in decimal format. you are using a value like this 32 01.2919, 34 54.7592 which is in degrees and minutes format, so that format must be converted to decimal before be passed to the javascript function. Now the reason because that value works in the google maps page is because that page internally resolves the string passed as parameter and returns a colletion of markers as result.

Math Parser in Delphi

So here is what I am trying to do:
I would like a parser that would evaluate equations and allow me to use custom functions. So, for example, an equation could be:
cos(5) * Patient:['lat1']
and it would let me have a function that does something if it finds Patient: in the expression.
The program I'm working on used a parser called MathParser (http://www.myart.bz/mathparser/), which worked fine in Delphi 2007, but has problems in Delphi XE (because of unicode). The MathParser site has a new version for XE, which I installed, but some functions have been changed around and I'm trying to get it to work right.
So, the problem seems to be with the custom function part, since everything else works fine.
The way I'm adding the functions is:
MathParser.AddFunction('Patient:', FPatFunction, fkMethod, FunctionMethod(PatFunction, 1),
False, False, vtDouble);
MathParser.AddFunction('Organ:', FOrgFunction, fkMethod, FunctionMethod(OrganFunction, 1),
False, False, vtDouble);
And then the functions themselves are
// patient function
function CEquatCalc.PatFunction(const AFunction: PFunction; const AType: PType;
const ParameterArray: TParameterArray): TValue;
begin
if Assigned(FPatient) and Assigned(FOrgan) then
AssignDouble(Result, (FPatient as CPatientItem).GetScoreVal((Trim(ParameterArray[0].Text)), (FOrgan as COrganItem)))
else if Assigned(FPatient) then
AssignDouble(Result,(FPatient as CPatientItem).GetScoreVal((Trim(ParameterArray[0].Text)), NIL));
end;
// organ function
function CEquatCalc.OrganFunction(const AFunction: PFunction; const AType: PType;
const ParameterArray: TParameterArray): TValue;
begin
AssignDouble(Result, (FOrgan as COrganItem).GetScoreVal((Trim(ParameterArray[0].Text))));
end;
The error that pops up says something like "Unknown element: lat1". Unfortunately since the component didn't come with Parser.pas (just the dcu file), I can't debug where it's happening.
Hopefully someone knows what the problem is, and if not, could you recommend another parser that would do what I want? (and is preferably free)
There are several nice free solutions for evaluating expressions at runtime now. Check out the answers to this question.
TbcParser does what you want. It is a math parser component for Delphi. It allows custom functions, and variables.
If you do have JVCL then it have an expression evaluating component too - JvInterpreter.
Not sure if it does exactly what you want, but you may give Pegtop math components
a try.

Resources