SRL Archive - OSR Help

ConvertTime issues..


shebee

2013-03-18 22:47:03

Basically my ConvertTime only returns with the hour but no minutes or seconds in my proggy.

[PHP]ConvertTime(((XPToNext / XPPerHour) * 3600000), h, m, s);
Writeln(IntToStr(h) + 'h:' + IntToStr(m) + 'm:' + IntToStr(s));[/PHP]
I've got h, m, s vars set in the procedure.

Output is something like this:
[PHP]3h:0m:0[/PHP]

I can't find how the ConvertTime procedure works exactly so I'm a little lost here.
Edit:


Ok so I printed the value in my proggy for debugging and it returns 10800000 and not 11303192 (rounded) as it should…

Le Jingle

2013-03-18 23:01:00

Could just use:

function MsToTime(MS, TheType: Integer): string;
which uses ConvertTime

Note: the acceptable arg for TheType is:

(*
- Time_Formal: 2 Hours, 47 Minutes and 28 Seconds
- Time_Short: 02h, 47m, 28s
- Time_Abbrev: 2 hr, 47 min, 28 sec
- Time_Bare: 02:47:28
- Time_FStop: 12.04.40
*)

so

Writeln(MsToTime(GetTimerunning(), Time_Formal));

shebee

2013-03-18 23:18:08

From: Le Jingle
Could just use:

function MsToTime(MS, TheType: Integer): string;
which uses ConvertTime

Note: the acceptable arg for TheType is:

(*
- Time_Formal: 2 Hours, 47 Minutes and 28 Seconds
- Time_Short: 02h, 47m, 28s
- Time_Abbrev: 2 hr, 47 min, 28 sec
- Time_Bare: 02:47:28
- Time_FStop: 12.04.40
*)

so

Writeln(MsToTime(GetTimerunning(), Time_Formal));



It still just returns BS…
Seems it rounds the time or something, so from 3h it went to 2h, and when I calculated it myself the real time was like 2h 57min.

Le Jingle

2013-03-18 23:24:00


{$include srl/srl.simba}
var
t: Integer;

begin
SetupSRL;
t := 60 * 1000;
t := t * 60;
t := t * 3;

// t now equals 3 hours in milliseconds
// let's add some randomness to it for better results.

t := t + Random(300000); // +/- 5 minutes

Writeln(MsToTime(t, Time_Formal));

end.

shebee

2013-03-18 23:32:04

From: Le Jingle

{$include srl/srl.simba}
var
t: Integer;

begin
SetupSRL;
t := 60 * 1000;
t := t * 60;
t := t * 3;

// t now equals 3 hours in milliseconds
// let's add some randomness to it for better results.

t := t + Random(300000); // +/- 5 minutes

Writeln(MsToTime(t, Time_Formal));

end.


Could it be that simba/pascal somehow rounds up the number when I divide?
Because it doesn't make any sense.
I think it's because I'm using integers and the result of the division is crazy, maybe extended type?
Edit:

I tried using int64 and ConvertTime64, but still I'm getting retarded results..
So I had another idea, just writeln the result as it is for hours, but I'm having problems with minutes.
If simba supported all pascal stuff I could use [PHP](frac(x)*60)[/PHP]for the minutes but I haven't figure out how to deal with it yet.

Any ideas on how to overcome this?

Edit:
Ok so I figured it out, if I do this:
[PHP] x := (10 / 3);

writeln(tostr(x)); [/PHP]
I get 3, but when I do this and set both variables as extended it works.
[PHP] y := 10;
x := (y / 3);

writeln(tostr(x)); [/PHP]
Is there any easier way of doing this?
Really annoying to define variables each time…
Something like (10:extended / 3:extended) or some shit :d