Friday, July 12, 2013

Calculate the firefox year with using Seq.unfold #2

(continued from phosphorescence: Calculate the firefox year with using Seq.unfold)

To refine more readable, adapt Active Pattern.

open System
let (|IsBetweenDate|) (targetDate, currentDate, nextDate) =
  (DateTime.Compare(targetDate, currentDate)>0, DateTime.Compare(targetDate, nextDate)>0)
let firefoxRollingReleaseDate n =
  let firefox5ReleaseDate = new DateTime(2011, 6, 21)
  let firefox6ReleaseDate = firefox5ReleaseDate.AddDays(7.0 * 8.0)
  let firefoxRollingRelease (currentDate:DateTime, nextDate:DateTime) =
    match (new DateTime(2012, 12, 25), nextDate, nextDate.AddDays(7.0 * 6.0)) with
    | IsBetweenDate (true, false) -> Some(currentDate, (nextDate, nextDate.AddDays(7.0 * 7.0)))
    | IsBetweenDate _ -> Some(currentDate, (nextDate, nextDate.AddDays(7.0 * 6.0)))
  match n < 5 with
  | true -> failwith "The version was not yet in rolling release."
  | _ -> Seq.nth (n - 5) <| Seq.unfold firefoxRollingRelease (firefox5ReleaseDate, firefox6ReleaseDate)

No comments:

Post a Comment