aboutsummaryrefslogtreecommitdiff
path: root/TJLaskuri.Core
diff options
context:
space:
mode:
authorJoel Stålnacke <joel@saker.fi>2025-08-01 20:22:50 +0300
committerJoel Stålnacke <joel@saker.fi>2025-08-01 20:22:50 +0300
commit40525e4f0ff494a3b5bf9cebad5d00ac25a3d840 (patch)
tree0a2cdf34f68f8a194a20e4c26afdbac771084c72 /TJLaskuri.Core
Basic domain logic
Diffstat (limited to 'TJLaskuri.Core')
-rw-r--r--TJLaskuri.Core/Library.fs27
-rw-r--r--TJLaskuri.Core/TJLaskuri.Core.fsproj13
-rw-r--r--TJLaskuri.Core/Types.fs42
3 files changed, 82 insertions, 0 deletions
diff --git a/TJLaskuri.Core/Library.fs b/TJLaskuri.Core/Library.fs
new file mode 100644
index 0000000..aa7b7ea
--- /dev/null
+++ b/TJLaskuri.Core/Library.fs
@@ -0,0 +1,27 @@
+namespace TJLaskuri.Core
+
+open System
+
+module Domain =
+ // TODO: More precise time: hours, minutes
+ // TODO: Time until service starts
+
+ let getStartDate kontingent =
+ match serviceStartDates.TryGetValue(kontingent) with
+ | true, startDate -> Some startDate
+ | false, _ -> None
+
+ let getEndDate kontingent serviceTime =
+ getStartDate kontingent
+ |> Option.map (fun startDate ->
+ ServiceTime.getDays serviceTime
+ |> fun x -> x - 1 // Count start date as well
+ |> startDate.AddDays)
+
+ let getTimeCompleted kontingent (now : DateTime) =
+ getStartDate kontingent
+ |> Option.map (fun date -> now.AddDays(1) - date)
+
+ let getTimeLeft kontingent serviceTime (now : DateTime) =
+ getEndDate kontingent serviceTime
+ |> Option.map (fun date -> date - now)
diff --git a/TJLaskuri.Core/TJLaskuri.Core.fsproj b/TJLaskuri.Core/TJLaskuri.Core.fsproj
new file mode 100644
index 0000000..c3b606a
--- /dev/null
+++ b/TJLaskuri.Core/TJLaskuri.Core.fsproj
@@ -0,0 +1,13 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>net9.0</TargetFramework>
+ <GenerateDocumentationFile>true</GenerateDocumentationFile>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Compile Include="Types.fs" />
+ <Compile Include="Library.fs" />
+ </ItemGroup>
+
+</Project>
diff --git a/TJLaskuri.Core/Types.fs b/TJLaskuri.Core/Types.fs
new file mode 100644
index 0000000..0c5b2d4
--- /dev/null
+++ b/TJLaskuri.Core/Types.fs
@@ -0,0 +1,42 @@
+namespace TJLaskuri.Core
+
+open System
+open System.Collections.Generic
+
+[<AutoOpen>]
+module Types =
+ /// Saapumiserä/kontingent N/Year
+ /// For example, 2/25 is { N = 2; Year = 2025 }
+ // Year field is first so that kontingents are sorted year first
+ type Kontingent = { Year : int; N : int }
+
+ type ServiceTime =
+ | OneSixFive
+ | TwoFiveFive
+ | ThreeFourSeven
+
+ module ServiceTime =
+ let getDays = function
+ | OneSixFive -> 165
+ | TwoFiveFive -> 255
+ | ThreeFourSeven -> 347
+
+ let kontingent n year = { N = n; Year = year }
+
+ let serviceStartDates =
+ let date day month year =
+ DateTime((year : int), month, day)
+ let entry n year endDate =
+ let k = kontingent n year
+ KeyValuePair<Kontingent, DateTime>(
+ k, endDate)
+
+ Dictionary<Kontingent, DateTime>([
+ entry 2 2024 (date 8 7 2024)
+ entry 1 2025 (date 6 1 2025)
+ entry 2 2025 (date 7 7 2025)
+ entry 1 2026 (date 5 1 2026)
+ entry 2 2026 (date 6 7 2026)
+ entry 1 2027 (date 4 1 2027)
+ entry 2 2027 (date 5 7 2027)
+ ])