Tuesday, October 2, 2012

Calculate the firefox year #2 (Fixed)

(Check also phosphorescence: Calculate the firefox year #2)

Firefox team announced changing their "Rapid release" plan.
I fix previous "Calculate the firefox year" F# code for this change.
module FirefoxReleaseDate =
  let calculateIn version =
    let calculateAddDays (currentDate:System.DateTime) =
      let happyHoliday = new System.DateTime(currentDate.Year, 12, 25)
      match ( (happyHoliday.Year >= 2012), (happyHoliday <= currentDate.AddDays(7.0 * 6.0)) ) with
      | (true, true) -> currentDate.AddDays(7.0 * 7.0)
      | _ -> currentDate.AddDays(7.0 * 6.0)
    let rec nextFirefoxReleaseDate (currentDate:System.DateTime) (currentVersion) =
        match currentVersion with
        | currentVersion when currentVersion >= version -> currentDate
        | _ -> nextFirefoxReleaseDate (calculateAddDays(currentDate)) (currentVersion + 1)
    let ver5ReleaseDate = new System.DateTime(2011, 6, 21)
    match version with
    | version when version >= 7 -> nextFirefoxReleaseDate (ver5ReleaseDate.AddDays(7.0 * 8.0)) 6
    | 6 -> ver5ReleaseDate.AddDays(7.0 * 8.0)
    | 5 -> ver5ReleaseDate
    | _ -> printfn "Not supported."; ver5ReleaseDate

  let calculateFirefoxYear =
    let rec incrementFirefoxYear (n:int) =
        let date = calculateIn(n)
        if n < date.Year
        then incrementFirefoxYear (n+1)
        else (n, date)
    incrementFirefoxYear(5)

let result = FirefoxReleaseDate.calculateFirefoxYear
let firefoxYearVersion = fst result
let firefoxYearDate = snd result
System.Console.WriteLine("The version equals release year ({0}) ({1:d})", firefoxYearVersion, firefoxYearDate)
System.Console.WriteLine("The version passes release year ({0}) ({1:d})", firefoxYearVersion+1, FirefoxReleaseDate.calculateIn(firefoxYearVersion+1))

No comments:

Post a Comment