@@ -185,6 +185,145 @@ TimeSpan.FromMilliseconds(1L, 0L) |> ignore
185185 |> Assert.Code.noWarning " FABLE0105"
186186 |> ignore
187187
188+ testCase " DateTime from non-constant ticks reports the dropped precision" <| fun _ ->
189+ let source =
190+ """
191+ open System
192+ let f (ticks: int64) = DateTime(ticks)
193+ """
194+ compile source
195+ |> Assert.Code.warning " FABLE0122"
196+ |> ignore
197+
198+ testCase " DateTime from constant ticks with a sub-millisecond part reports the dropped precision" <| fun _ ->
199+ let source =
200+ """
201+ open System
202+ DateTime(630822816000012345L, DateTimeKind.Utc) |> ignore
203+ """
204+ compile source
205+ |> Assert.Code.warning " FABLE0122"
206+ |> ignore
207+
208+ testCase " DateTime with non-zero microseconds reports the dropped precision" <| fun _ ->
209+ let source =
210+ """
211+ open System
212+ DateTime(2020, 1, 1, 0, 0, 0, 0, 250) |> ignore
213+ DateTime(2020, 1, 1, 0, 0, 0, 0, 250, DateTimeKind.Utc) |> ignore
214+ """
215+ compile source
216+ |> Assert.Code.warning " FABLE0122"
217+ |> ignore
218+
219+ testCase " DateTime.AddTicks with non-constant ticks reports the dropped precision" <| fun _ ->
220+ let source =
221+ """
222+ open System
223+ let f (d: DateTime) (ticks: int64) = d.AddTicks ticks
224+ """
225+ compile source
226+ |> Assert.Code.warning " FABLE0122"
227+ |> ignore
228+
229+ testCase " DateTimeOffset from non-constant ticks reports the dropped precision" <| fun _ ->
230+ let source =
231+ """
232+ open System
233+ let f (ticks: int64) = DateTimeOffset(ticks, TimeSpan.Zero)
234+ """
235+ compile source
236+ |> Assert.Code.warning " FABLE0122"
237+ |> ignore
238+
239+ testCase " DateTimeOffset with non-constant microseconds reports the dropped precision" <| fun _ ->
240+ let source =
241+ """
242+ open System
243+ let f (us: int) = DateTimeOffset(2020, 1, 1, 0, 0, 0, 0, us, TimeSpan.Zero)
244+ """
245+ compile source
246+ |> Assert.Code.warning " FABLE0122"
247+ |> ignore
248+
249+ testCase " DateTimeOffset.AddTicks with a sub-millisecond part reports the dropped precision" <| fun _ ->
250+ let source =
251+ """
252+ open System
253+ let f (d: DateTimeOffset) = d.AddTicks 5L
254+ """
255+ compile source
256+ |> Assert.Code.warning " FABLE0122"
257+ |> ignore
258+
259+ testCase " TimeSpan from non-constant ticks reports the dropped precision" <| fun _ ->
260+ let source =
261+ """
262+ open System
263+ let f (ticks: int64) = TimeSpan ticks, TimeSpan.FromTicks ticks
264+ """
265+ compile source
266+ |> Assert.Code.warning " FABLE0122"
267+ |> ignore
268+
269+ testCase " TimeSpan with non-zero microseconds reports the dropped precision" <| fun _ ->
270+ let source =
271+ """
272+ open System
273+ TimeSpan(0, 0, 0, 0, 1, 250) |> ignore
274+ """
275+ compile source
276+ |> Assert.Code.warning " FABLE0122"
277+ |> ignore
278+
279+ testCase " TimeOnly from non-constant ticks reports the dropped precision" <| fun _ ->
280+ let source =
281+ """
282+ open System
283+ let f (ticks: int64) = TimeOnly ticks
284+ """
285+ compile source
286+ |> Assert.Code.warning " FABLE0122"
287+ |> ignore
288+
289+ testCase " TimeOnly with non-zero microseconds reports the dropped precision" <| fun _ ->
290+ let source =
291+ """
292+ open System
293+ TimeOnly(1, 2, 3, 4, 250) |> ignore
294+ """
295+ compile source
296+ |> Assert.Code.warning " FABLE0122"
297+ |> ignore
298+
299+ testCase " Date and time values with no sub-millisecond part are silent" <| fun _ ->
300+ let source =
301+ """
302+ open System
303+ DateTime(630822816000010000L) |> ignore
304+ DateTime(630822816000010000L, DateTimeKind.Utc) |> ignore
305+ DateTime(2020, 1, 1, 0, 0, 0, 0, 0) |> ignore
306+ DateTime(2020, 1, 1, 0, 0, 0, 0, 0, DateTimeKind.Utc) |> ignore
307+ DateTime(2020, 1, 1, 0, 0, 0, 5, DateTimeKind.Utc) |> ignore
308+ DateTime(2020, 1, 1).AddTicks(10000L) |> ignore
309+ DateTimeOffset(630822816000010000L, TimeSpan.Zero) |> ignore
310+ DateTimeOffset(2020, 1, 1, 0, 0, 0, 0, 0, TimeSpan.Zero) |> ignore
311+ DateTimeOffset(2020, 1, 1, 0, 0, 0, 5, TimeSpan.Zero) |> ignore
312+ DateTimeOffset(2020, 1, 1, 0, 0, 0, TimeSpan.Zero).AddTicks(-20000L) |> ignore
313+ TimeSpan(10000L) |> ignore
314+ TimeSpan.FromTicks(0L) |> ignore
315+ TimeSpan(0, 0, 0, 0, 1, 0) |> ignore
316+ TimeSpan(1, 2, 3) |> ignore
317+ TimeOnly(10000L) |> ignore
318+ TimeOnly(1, 2, 3, 4, 0) |> ignore
319+ TimeOnly(1, 2, 3, 4) |> ignore
320+ let f (ms: int) = DateTime(2020, 1, 1, 0, 0, 0, ms), TimeSpan(0, 0, 0, 0, ms), TimeOnly(1, 2, 3, ms)
321+ let g (d: DateTime) (o: DateTimeOffset) = DateTime(d.Ticks, DateTimeKind.Utc), DateTimeOffset(o.Ticks, o.Offset)
322+ """
323+ compile source
324+ |> Assert.Code.noWarning " FABLE0122"
325+ |> ignore
326+
188327 testCase " A private-representation flag on FSharpType is reported" <| fun _ ->
189328 let source =
190329 """
0 commit comments