Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Fable.Transforms/Beam/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5036,6 +5036,9 @@ let private dateTimeOffsets
(args: Expr list)
=
match info.CompiledName with
| "op_Implicit" ->
Helper.LibCall(com, "fable_date_offset", "from_date", t, args @ [ makeIntConst 0 ], ?loc = r)
|> Some
| ".ctor" ->
match args with
| [] -> Helper.LibCall(com, "fable_date_offset", "min_value", t, [], ?loc = r) |> Some
Expand Down
3 changes: 3 additions & 0 deletions src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3191,6 +3191,9 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio
"DateOffset"

match i.CompiledName with
| "op_Implicit" ->
Helper.LibCall(com, "DateOffset", "fromDate", t, args, i.SignatureArgTypes, ?loc = r)
|> Some
| ".ctor" ->
match args with
| [] -> Helper.LibCall(com, moduleName, "minValue", t, [], [], ?loc = r) |> Some
Expand Down
1 change: 1 addition & 0 deletions src/Fable.Transforms/Rust/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2652,6 +2652,7 @@ let dateTimeOffsets (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg:
_offset ] -> "new_ymdhms_micro" |> Some
| _ -> None
|> Option.map (fun meth -> makeStaticMemberCall com r t i "DateTimeOffset" meth args)
| "op_Implicit", _ -> makeStaticMemberCall com r t i "DateTimeOffset" "new_datetime" args |> Some
| ("Compare" | "CompareTo" | "Equals" | "GetHashCode"), thisArg -> valueTypes com ctx r t i thisArg args
| "Add", Some c ->
Operation(Binary(BinaryOperator.BinaryPlus, c, args.Head), Tags.empty, t, r)
Expand Down
13 changes: 13 additions & 0 deletions tests/Beam/DateTimeOffsetTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,16 @@
dt.Minute |> equal dt_exp.Minute
dt.Second |> equal dt_exp.Second
dt.Millisecond |> equal dt_exp.Millisecond

[<Fact>]
let ``test Implicit conversion from DateTime preserves value`` () =
let d = DateTime(2024, 1, 15, 13, 23, 30, DateTimeKind.Utc)
let dto: DateTimeOffset = d

Check warning on line 525 in tests/Beam/DateTimeOffsetTests.fs

View workflow job for this annotation

GitHub Actions / build-beam

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".
dto |> equal (DateTimeOffset(d))
dto.Offset |> equal TimeSpan.Zero
dto.Year |> equal 2024
dto.Month |> equal 1
dto.Day |> equal 15
dto.Hour |> equal 13
dto.Minute |> equal 23
dto.Second |> equal 30
13 changes: 13 additions & 0 deletions tests/Python/TestDateTimeOffset.fs
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,16 @@
dt.Minute |> equal dt_exp.Minute
dt.Second |> equal dt_exp.Second
dt.Millisecond |> equal dt_exp.Millisecond

[<Fact>]
let ``test Implicit conversion from DateTime preserves value`` () =
let d = DateTime(2024, 1, 15, 13, 23, 30, DateTimeKind.Utc)
let dto: DateTimeOffset = d

Check warning on line 576 in tests/Python/TestDateTimeOffset.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.15)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".

Check warning on line 576 in tests/Python/TestDateTimeOffset.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.13)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".

Check warning on line 576 in tests/Python/TestDateTimeOffset.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.15)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".

Check warning on line 576 in tests/Python/TestDateTimeOffset.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.13)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".

Check warning on line 576 in tests/Python/TestDateTimeOffset.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.14)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".

Check warning on line 576 in tests/Python/TestDateTimeOffset.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.14)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".
dto |> equal (DateTimeOffset(d))
dto.Offset |> equal TimeSpan.Zero
dto.UtcDateTime.Year |> equal 2024
dto.UtcDateTime.Month |> equal 1
dto.UtcDateTime.Day |> equal 15
dto.UtcDateTime.Hour |> equal 13
dto.UtcDateTime.Minute |> equal 23
dto.UtcDateTime.Second |> equal 30
13 changes: 13 additions & 0 deletions tests/Rust/tests/src/DateTimeOffsetTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,3 +1031,16 @@
let source = DateTimeOffset(2007, 9, 1, 14, 30, 0, TimeSpan.Zero)
(fun () -> source.ToOffset(TimeSpan(0, 0, -10)))
|> throwsErrorContaining "Offset must be specified in whole minutes"

[<Fact>]
let ``Implicit conversion from DateTime preserves value`` () =
let d = DateTime(2024, 1, 15, 13, 23, 30, DateTimeKind.Utc)
let dto: DateTimeOffset = d

Check warning on line 1038 in tests/Rust/tests/src/DateTimeOffsetTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (no_std)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".

Check warning on line 1038 in tests/Rust/tests/src/DateTimeOffsetTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (,)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".

Check warning on line 1038 in tests/Rust/tests/src/DateTimeOffsetTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (threaded)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".

Check warning on line 1038 in tests/Rust/tests/src/DateTimeOffsetTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (reflection)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".

Check warning on line 1038 in tests/Rust/tests/src/DateTimeOffsetTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (lrc_ptr)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".

Check warning on line 1038 in tests/Rust/tests/src/DateTimeOffsetTests.fs

View workflow job for this annotation

GitHub Actions / analyzers (src/Fable.AST/Fable.AST.fsproj)

This expression uses the implicit conversion 'DateTimeOffset.op_Implicit(dateTime: DateTime) : DateTimeOffset' to convert type 'DateTime' to type 'DateTimeOffset'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".
dto |> equal (DateTimeOffset(d))
dto.Offset |> equal TimeSpan.Zero
dto.Year |> equal 2024
dto.Month |> equal 1
dto.Day |> equal 15
dto.Hour |> equal 13
dto.Minute |> equal 23
dto.Second |> equal 30
Loading