Fixed expiration comparison (#17)
The comparison now forces the comparison on dates, excluding times
This commit is contained in:
parent
7d0e1484ba
commit
0748ad6ce8
@ -545,13 +545,13 @@ and [<CLIMutable; NoComparison; NoEquality>] PrayerRequest =
|
|||||||
match this.requestType with
|
match this.requestType with
|
||||||
| LongTermRequest
|
| LongTermRequest
|
||||||
| Expecting -> false
|
| Expecting -> false
|
||||||
| _ -> curr.AddDays(-(float expDays)) > this.updatedDate // Automatic expiration
|
| _ -> curr.AddDays(-(float expDays)).Date > this.updatedDate.Date // Automatic expiration
|
||||||
|
|
||||||
/// Is an update required for this long-term request?
|
/// Is an update required for this long-term request?
|
||||||
member this.updateRequired curr expDays updWeeks =
|
member this.updateRequired curr expDays updWeeks =
|
||||||
match this.isExpired curr expDays with
|
match this.isExpired curr expDays with
|
||||||
| true -> false
|
| true -> false
|
||||||
| false -> curr.AddDays(-(float (updWeeks * 7))) > this.updatedDate
|
| false -> curr.AddDays(-(float (updWeeks * 7))).Date > this.updatedDate.Date
|
||||||
|
|
||||||
/// Configure EF for this entity
|
/// Configure EF for this entity
|
||||||
static member internal configureEF (mb : ModelBuilder) =
|
static member internal configureEF (mb : ModelBuilder) =
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<AssemblyVersion>7.3.1.0</AssemblyVersion>
|
<AssemblyVersion>7.3.2.0</AssemblyVersion>
|
||||||
<FileVersion>7.3.1.0</FileVersion>
|
<FileVersion>7.3.2.0</FileVersion>
|
||||||
<Version>7.3.1</Version>
|
<Version>7.3.2</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -171,33 +171,42 @@ let prayerRequestTests =
|
|||||||
Expect.isTrue (req.isExpired DateTime.Now 5) "A force-expired request should always be considered expired"
|
Expect.isTrue (req.isExpired DateTime.Now 5) "A force-expired request should always be considered expired"
|
||||||
}
|
}
|
||||||
test "isExpired returns false for non-expired requests" {
|
test "isExpired returns false for non-expired requests" {
|
||||||
let req = { PrayerRequest.empty with updatedDate = DateTime.Now.AddDays -5. }
|
let now = DateTime.Now
|
||||||
Expect.isFalse (req.isExpired DateTime.Now 7) "A request updated 5 days ago should not be considered expired"
|
let req = { PrayerRequest.empty with updatedDate = now.AddDays -5. }
|
||||||
|
Expect.isFalse (req.isExpired now 7) "A request updated 5 days ago should not be considered expired"
|
||||||
}
|
}
|
||||||
test "isExpired returns true for expired requests" {
|
test "isExpired returns true for expired requests" {
|
||||||
let req = { PrayerRequest.empty with updatedDate = DateTime.Now.AddDays -8. }
|
let now = DateTime.Now
|
||||||
Expect.isTrue (req.isExpired DateTime.Now 7) "A request updated 8 days ago should be considered expired"
|
let req = { PrayerRequest.empty with updatedDate = now.AddDays -8. }
|
||||||
|
Expect.isTrue (req.isExpired now 7) "A request updated 8 days ago should be considered expired"
|
||||||
|
}
|
||||||
|
test "isExpired returns true for same-day expired requests" {
|
||||||
|
let now = DateTime.Now
|
||||||
|
let req = { PrayerRequest.empty with updatedDate = now.Date.AddDays(-7.).AddSeconds -1. }
|
||||||
|
Expect.isTrue (req.isExpired now 7) "A request entered a second before midnight should be considered expired"
|
||||||
}
|
}
|
||||||
test "updateRequired returns false for expired requests" {
|
test "updateRequired returns false for expired requests" {
|
||||||
let req = { PrayerRequest.empty with expiration = Forced }
|
let req = { PrayerRequest.empty with expiration = Forced }
|
||||||
Expect.isFalse (req.updateRequired DateTime.Now 7 4) "An expired request should not require an update"
|
Expect.isFalse (req.updateRequired DateTime.Now 7 4) "An expired request should not require an update"
|
||||||
}
|
}
|
||||||
test "updateRequired returns false when an update is not required for an active request" {
|
test "updateRequired returns false when an update is not required for an active request" {
|
||||||
|
let now = DateTime.Now
|
||||||
let req =
|
let req =
|
||||||
{ PrayerRequest.empty with
|
{ PrayerRequest.empty with
|
||||||
requestType = LongTermRequest
|
requestType = LongTermRequest
|
||||||
updatedDate = DateTime.Now.AddDays -14.
|
updatedDate = now.AddDays -14.
|
||||||
}
|
}
|
||||||
Expect.isFalse (req.updateRequired DateTime.Now 7 4)
|
Expect.isFalse (req.updateRequired now 7 4)
|
||||||
"An active request updated 14 days ago should not require an update until 28 days"
|
"An active request updated 14 days ago should not require an update until 28 days"
|
||||||
}
|
}
|
||||||
test "updateRequired returns true when an update is required for an active request" {
|
test "updateRequired returns true when an update is required for an active request" {
|
||||||
|
let now = DateTime.Now
|
||||||
let req =
|
let req =
|
||||||
{ PrayerRequest.empty with
|
{ PrayerRequest.empty with
|
||||||
requestType = LongTermRequest
|
requestType = LongTermRequest
|
||||||
updatedDate = DateTime.Now.AddDays -34.
|
updatedDate = now.AddDays -34.
|
||||||
}
|
}
|
||||||
Expect.isTrue (req.updateRequired DateTime.Now 7 4)
|
Expect.isTrue (req.updateRequired now 7 4)
|
||||||
"An active request updated 34 days ago should require an update (past 28 days)"
|
"An active request updated 34 days ago should require an update (past 28 days)"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
<AssemblyVersion>7.3.1.0</AssemblyVersion>
|
<AssemblyVersion>7.3.2.0</AssemblyVersion>
|
||||||
<FileVersion>7.3.1.0</FileVersion>
|
<FileVersion>7.3.2.0</FileVersion>
|
||||||
<Version>7.3.1</Version>
|
<Version>7.3.2</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<AssemblyVersion>7.3.1.0</AssemblyVersion>
|
<AssemblyVersion>7.3.2.0</AssemblyVersion>
|
||||||
<FileVersion>7.3.1.0</FileVersion>
|
<FileVersion>7.3.2.0</FileVersion>
|
||||||
<Version>7.3.1</Version>
|
<Version>7.3.2</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -55,7 +55,7 @@ module Configure =
|
|||||||
CookieCrypto (crypto.["Key"], crypto.["IV"]) |> setCrypto
|
CookieCrypto (crypto.["Key"], crypto.["IV"]) |> setCrypto
|
||||||
svc.AddDbContext<AppDbContext>(
|
svc.AddDbContext<AppDbContext>(
|
||||||
fun options ->
|
fun options ->
|
||||||
options.UseNpgsql(config.GetConnectionString "PrayerTracker") |> ignore)
|
options.UseNpgsql (config.GetConnectionString "PrayerTracker") |> ignore)
|
||||||
|> ignore
|
|> ignore
|
||||||
|
|
||||||
/// Routes for PrayerTracker
|
/// Routes for PrayerTracker
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
<AssemblyVersion>7.3.1.0</AssemblyVersion>
|
<AssemblyVersion>7.3.2.0</AssemblyVersion>
|
||||||
<FileVersion>7.3.1.0</FileVersion>
|
<FileVersion>7.3.2.0</FileVersion>
|
||||||
<Authors></Authors>
|
<Authors></Authors>
|
||||||
<Company>Bit Badger Solutions</Company>
|
<Company>Bit Badger Solutions</Company>
|
||||||
<Version>7.3.1</Version>
|
<Version>7.3.2</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user