1
\$\begingroup\$

explain:

from start day till now I've got 7.7 mb size, how long it will be to make it 10 gb size

open System

let dd = (DateTime.Now - DateTime.Parse("12/09/2012")).Days
let oneday = 7.7 / Convert.ToDouble(dd)

let in10gb = Convert.ToInt32( Math.Round (10.0 * 1024.0 / oneday) )
let years = Convert.ToInt32( Math.Round (float in10gb / 365.0) )
let mutable months = Convert.ToInt32( Math.Round (float (in10gb - years * 365) / 30.0) )
let days = 
    let d = in10gb - years * 365 - months * 30
    if d > 0 then d else month = month - 1; (30 - d)

printf "%d years %d months %d days" years months days
Console.ReadKey() |> ignore

Also / 30.0 for months is dirty hack here... I'm not sure how to avoid it in easy way.

\$\endgroup\$
  • \$\begingroup\$ Be careful with things like DateTime.Parse("12/09/2012"). They can give different results on different computes, due to culture settings. \$\endgroup\$ – svick Oct 29 '12 at 14:53
2
\$\begingroup\$

I would propose an alternative method of calculating your time, using seconds and DateTimes:

open System

let startDate = DateTime.Parse ("2012-09-12")
let now = DateTime.Now;
let currentRuntime = (now - startDate).TotalSeconds
let timePerGig = currentRuntime / 7.7;
let tenDate = startDate + TimeSpan.FromSeconds (10.0 * timePerGig);

With that done, you can do whatever you like to represent the final date relative to the current date.

An overly simplistic example is as follows:

printf "%d years %d months %d days" (finalDate.Year - now.Year) (finalDate.Month - now.Month) (finalDate.Day - now.Day)

Of course, you would have to account for roll-over for days and months in any final piece of code, but it illustrates how you could pull the date parts back out.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.