Solved

How to calc minutes to Week - Days- Hours- Min of a working 1 days = 8 hours en 40 hours = 1 week

Posted on 2006-06-22
15
262 Views
Last Modified: 2010-04-05
Hoi,

I have make somthing, but it wont work correcly.
Please help my

inttotimestr(2123333) = result 73d 05:43:04:53 ????????

function inttotimestr(S: integer): string;   // z.B. 3600-> '01:00:00'
var
  st:string;
  ti,t:integer;
begin

  try
    st:='';
    if (s > 28800) then begin
      st:=inttostr(s div 28800)+'d ';
    end;
    s:=s mod 28800;

    if (s div 480) = 0 then
      st:=st+'00:'
    else if (s div 480) < 10 then
      st:=st+'0'+inttostr(s div 480)+':'
    else
      st:=st+inttostr(s div 480)+':';

    ti:=s mod 480;
    if (ti div 60) = 0 then
      st:=st+'00:'
    else if (ti div 60) < 10 then
      st:=st+'0'+inttostr(ti div 60)+':'
    else
      st:=st+inttostr(ti div 60)+':';

    t:=ti mod 60;
    if t = 0 then
      st:=st+'00'
    else if t < 10 then
      st:=st+'0'+inttostr(t)
    else
      st:=st+inttostr(t);
  except
    st:='00:00:00';
  end;
  inttotimestr:=st;
end;


0
Comment
Question by:kuken1
  • 6
  • 6
  • 2
  • +1
15 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 16964733
hm... you are making some errors from the start: are you talking about minutes or seconds?

here is a routine I made, because I just can't make out what you want to do. This will convert a number of minutes, to week,day, hour, minute, considering that 1 week has 5 days, 1 day has 8 hours and 1 hour has 60 seconds.

function inttotimestr(s:integer):string;// input is minutes
var w,d,h,m:word;
begin
  w:=s div (5*8*60);// 5 days with 8 hours having 60 min
  s:=s mod (5*8*60);
  d:=s div (8*60);
  s:=s mod (8*60);
  h:=s div 60;
  m:=s mod 60;
  result:=format('%d:%.2d:%.2d:%.2d',[w,d,h,m]);
end;
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 16964808
Example that breaks the minutes down to weeks (40 hrs) , days (8 hrs) and remaining hours:minutes:seconds

Regards,
Russell


function MinutesToWorkTime(Minutes: Integer): String;
var  dwTime:     Array [0..4] of Integer;
     dwCurrent:  Integer;
begin

  // Calculate weeks
  dwTime[0]:=Minutes div 144000;
  dwCurrent:=Minutes mod 144000;

  // Calculate days
  dwTime[1]:=dwCurrent div 28800;
  dwCurrent:=dwCurrent mod 28800;

  // Calculate hours
  dwTime[2]:=dwCurrent div 3600;
  dwCurrent:=dwCurrent mod 3600;

  // Calculate minutes
  dwTime[3]:=dwCurrent div 60;
  dwCurrent:=dwCurrent mod 60;

  // Calculate seconds
  dwTime[4]:=dwCurrent;

  // Set result
  SetLength(result, 0);

  // Build string with weeks and days
  if (dwTime[0] > 0) then result:=IntToStr(dwTime[0])+'w';
  if (dwTime[1] > 0) then
  begin
     if (Length(result) > 0) then
        result:=result+' '+IntToStr(dwTime[1])+'d'
     else
        result:=result+' '+IntToStr(dwTime[1])+'d';
  end;

  // Add remaining hours:minutes:seconds
  if (Length(result) > 0) then
     result:=result+Format(' %.2d:%.2d:%.2d', [dwTime[2], dwTime[3], dwTime[4]])
  else
     result:=result+Format('%.2d:%.2d:%.2d', [dwTime[2], dwTime[3], dwTime[4]]);

end;

0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 16964844
My bad, I was using seconds on the calculations...

Russell
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:kuken1
ID: 16966601
hoi rllibby,

I have test our solutions. i see the
By great number workt it. (great !)
test 1 example result 2123333 min = 14w 3d 05:48:53
test 2 example result 810 min =   00:13:30 ??? must by 1d:05:30:00  
test 3 example result 510 min =   00:08:30 ist OK ?  
it wont work correcly with small numbers ?
0
 
LVL 28

Expert Comment

by:2266180
ID: 16966706
I am still confused about this:

if you are inputting minutes, how are you getting non-zero seconds?

I adapted my code to seconds input and indeed now I am getting your desired results. so you don't inputmin, you input seconds.

regarding your "small numbers"
810 seconds are 13 min and 30 seconds not 1 day 5 hours and 30 min

function inttotimestr(s:integer):string;// input is minutes
var w,d,h,m,se:word;
begin
  w:=s div (5*8*60*60);// 5 days with 8 hours having 60 min
  s:=s mod (5*8*60*60);
  d:=s div (8*60*60);
  s:=s mod (8*60*60);
  h:=s div (60*60);
  s:=s mod (60*60);
  m:=s div 60;
  se:=s mod 60;
  result:=format('%d:%.2d:%.2d:%.2d:%.2d',[w,d,h,m,se]);
end;
0
 
LVL 28

Expert Comment

by:2266180
ID: 16966712
here is code with changed formatting to output as you requested:

function inttotimestr(s:integer):string;// input is seconds
var w,d,h,m,se:word;
begin
  w:=s div (5*8*60*60);// 5 days with 8 hours having 60 min
  s:=s mod (5*8*60*60);
  d:=s div (8*60*60);
  s:=s mod (8*60*60);
  h:=s div (60*60);
  s:=s mod (60*60);
  m:=s div 60;
  se:=s mod 60;
  result:=format('%dw %dd %.2d:%.2d:%.2d',[w,d,h,m,se]);
end;
0
 
LVL 10

Accepted Solution

by:
atul_parmar earned 500 total points
ID: 16966830
Just call MinutesBetween function.

:)
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16966842
Also see

MinuteOf
MinuteOfTheDay
MinuteOfTheHour
MinuteOfTheMonth
MinuteOfTheWeek
MinuteOfTheYear
MinutesBetween
MinuteSpan
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16967106
B ??????????????????????
0
 
LVL 28

Expert Comment

by:2266180
ID: 16967131
but of course. you didn't provide code on how to use it. beside that not answering the question :P I just can't figure out how to use those minute* functions to achieve what the asker wanted (convert minute or seconds, still not clear to a string representation with weeks, days, etc).
so B is more than enough :P


a little sarcastic this morning :D
i'm in a good mood, though I have a papre due in 30 minutes and it's ... far from ready. and instead of working on that, I am writing this. totally illogical.

oh well, back to my paper :)
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16967203
For Delphi programmer at least I can expect that he knows how to call a simple function. :)
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16967218
Btw, all the best Ciuly!! Infect, instead of all the best I must say Congratulates!!
0
 
LVL 28

Expert Comment

by:2266180
ID: 16967266
hehe, calling is not the issue, rather the usage. AFAIK, minutesbetween takes 2 TDateTime's as arguments and spit's out an integer if I am correct (I'm not starting uup the ide cause I've got a few stuff opena dn only 256 mb of ram :( )
now ... we have an integer as input... so the usage is a little tricky.

btw, I have woken up for quite some hours, but I can't figure out what are the congratulations for.
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16967293
Re:
i'm in a good mood, though I have a papre due in 30 minutes and it's ... far from ready. and instead of working on that, I am writing this. totally illogical.

oh well, back to my paper :)


For ppl I m confident on, I say Congrats rather than All the Best! (i.e. I dont wait for result)
0
 
LVL 28

Expert Comment

by:2266180
ID: 16967386
oh, that makes sense now :))
thanks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question