Results 1 to 7 of 7

Thread: IntToTime

  1. #1
    Join Date
    May 2007
    Location
    England
    Posts
    4,141
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default IntToTime

    SCAR Code:
    {*******************************************************************************
    function IntToTime(MS : Integer) : string;
    By: R1ch
    Description: Converts MS to H/M/S/MS time
    *******************************************************************************}

    function IntToTime(MS : Integer) : string;
    var
      I : Integer;
      HMS, HMSc : TIntegerArray;

    begin
      HMS:= [1000, 60000, 3600000];
      SetLength(HMSc, 3);
      for I:= 2 downto 0 do
      begin
        repeat
          if (MS > HMS[I]) then
          begin
            MS:= MS - HMS[I];
            Inc(HMSc[I]);
          end;
        until(MS < HMS[I]);
      end;
      Result:= (IntToStr(HMSc[2]) + ' Hours, ' + IntToStr(HMSc[1]) + ' Minutes, ' + IntToStr(HMSc[0]) + ' Seconds and ' + IntToStr(MS) + ' Milliseconds');
    end;

    Converts milliseconds to hours, minutes, seconds and milliseconds.

    Example:

    IntToTime(5214622);

    outputs

    1 Hours, 26 Minutes, 54 Seconds and 622 Milliseconds

    It is used like:
    SCAR Code:
    WriteLn(IntToTime(5214622));

    Richard.
    Last edited by Rich; 08-26-2009 at 11:28 PM.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  2. #2
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Nice =). I often did that "manually". Such function is quite usefull .
    *saves it to ownsrlinclude.scar* .

    ~caused

  3. #3
    Join Date
    May 2007
    Location
    England
    Posts
    4,141
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Thanks. You do know there is another function out there which does this - MsToTime? I only remembered after I'd made this though.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  4. #4
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by R1ch View Post
    Thanks. You do know there is another function out there which does this - MsToTime? I only remembered after I'd made this though.
    really?... Well yours sounds much cooler :'D. So, when i need it ill use yours and add some credits .

    ~caused

  5. #5
    Join Date
    May 2007
    Location
    England
    Posts
    4,141
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Timing.scar
    SCAR Code:
    function MsToTime(MS, TheType: Integer): string;
    var
      STA: array [0..4] of TVariantArray;
      Time: array [0..2] of Integer;
      i: Integer;
    begin
      Result := '';
      if (not(InRange(TheType, 0, High(STA)))) then
      begin
        srl_Warn('MsToTime', 'TheType: ''' + IntToStr(TheType) + ''' is not a valid value. Using Time_Bare.', warn_AllVersions);
        TheType := Time_Bare;
      end;

      STA[0] := [' Hours, ', ' Minutes and ', ' Seconds', False, 0];
      STA[1] := ['h ', 'm ', 's', False, 2];
      STA[2] := [' hr ', ' min ', ' sec', False, 0];
      STA[3] := [':', ':', '', True, 2];
      STA[4] := ['.', '.', '', True, 2];

      ConvertTime(MS, Time[0], Time[1], Time[2]);
      for i := 0 to 2 do
        if (Time[i] > 0) or (STA[TheType][3]) or (i = 2) then
          Result := Result + PadZ(IntToStr(Time[i]), STA[TheType][4]) + STA[TheType][i];
    end;
    However, for what it does, MSToTime seems to be over-complicated, I think.

    Thanks,
    Richard.
    Last edited by Rich; 08-26-2009 at 11:29 PM.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  6. #6
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    Not getting included...

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  7. #7
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    MSToTime allows for MANY different formats

    Edit: Is also faster.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •