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 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 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 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
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
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 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
/// <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
type symbol = Number of int | Plus | Minus | |
let rec calc (s: symbol list) : int = | |
match s with | |
| [] -> 0 | |
| [Number x] -> x | |
| Number x :: Number y :: rest -> calc(Number ((int)(sprintf "%d%d" x y)) :: rest) | |
| Number x :: rest -> x + calc(rest) | |
| Plus :: rest -> + calc(rest) | |
| Minus :: rest -> - calc(rest) |
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 symbol = Number of int | Plus of int * symbol | Minus of int * symbol | Noop of int * symbol | |
let merge (i1: int) (i2:int) = (int)(sprintf "%d%d" i1 i2) | |
let rec flattenNoop ((i,s): (int*symbol)) = | |
match s with | |
| Number n -> Number (merge i n) | |
| Plus (n,t) -> Plus (merge i n,t) | |
| Minus (n,t) -> Minus (merge i n,t) | |
| Noop (n,t) -> flattenNoop (merge i n,t) |