This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Encodes for storing in Azure Table store to get correct ordering | |
/// </summary> | |
/// <param name="date">Use UTC</param> | |
public static string InverseDateTime(this DateTime date) | |
{ | |
var newDate = DateTime.MaxValue.Ticks - date.Ticks; | |
return newDate.ToString(CultureInfo.InvariantCulture); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let datetimetest (date1 :System.DateTime) (date2: System.DateTime) = | |
let inverseDate1 = DateFormatInverter.InverseDateTime(date1) | |
let inverseDate2 = DateFormatInverter.InverseDateTime(date2) | |
if (date1 > date2) then | |
inverseDate1 < inverseDate2 | |
else if (date1 < date2) then | |
inverseDate1 > inverseDate2 | |
else | |
inverseDate1 = inverseDate2 | |
Check.QuickThrowOnFailure datetimetest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let findHoursInNorwegianDay (year:int) (month:int) (day: int) :int = | |
let zone = DateTimeZoneProviders.Tzdb.GetZoneOrNull("Europe/Oslo") | |
let t1 = new LocalDateTime(year, month,day,0,0) | |
let t2 = t1.PlusDays(1) | |
let z1 = t1.InZoneLeniently(zone) | |
let z2 = t2.InZoneLeniently(zone) | |
let interval = z2.ToInstant()- z1.ToInstant() | |
int (System.Math.Round(TimeSpan.FromTicks(interval.Ticks).TotalHours,0)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let getLastSundays year = | |
let lastSundays = Dictionary<int, int>() | |
// find all lastsundays | |
[for month in 1..12-> | |
[for day in System.DateTime.DaysInMonth(year,month).. -1.. 1-> | |
System.DateTime(year,month,day).DayOfWeek,(month,day)] | |
|> Seq.find (fun (dayOfWeek,_) -> dayOfWeek = System.DayOfWeek.Sunday) ] | |
|> Seq.map (fun ((_,x)) -> x) |> Seq.iter lastSundays.Add | |
lastSundays |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type hourReading = int * meterReading |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type norTimestamp = ZonedDateTime | |
type utcTimestamp = Instant | |
type meterReading= { Val: decimal } // Contains more stuff, shortend for clarity | |
type utcReading = utcTimestamp * meterReading | |
type norReading = norTimestamp * meterReading |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type reading<'A> = { TimeStamp: 'A; | |
Value: decimal} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type timestamp= NorwegianTimeStamp of ZonedDateTime | UtcTimeStamp of Instant | |
type reading = { TimeStamp: timestamp; | |
Value: decimal} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type foo<'A> = { Name: string; things : 'A list} | |
let bar = { Name = "Bjorn"; things = [1;2;3;4]} | |
let baz = {Name = bar.Name; things = bar.things |> List.map (fun x -> x.ToString())} | |
let baznoworky = { bar with things = (bar.things |> List.map (fun x -> x.ToString()))} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
// We can not work with radius of the diamond outside 0 to 25 | |
let CreateRadius (i:int) = | |
match i with | |
| i when i = 0 && i < 26 -> Some i | |
| _ -> None | |
let radius = CreateRadius 20 |> Option.get | |
let axis = [|-radius .. radius|] |