Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Trying to print datetime throws NotImplementedError: date_to_string_with_offset #3854

Open
Freymaurer opened this issue Jun 17, 2024 · 1 comment

Comments

@Freymaurer
Copy link

Description

Trying to print System.DateTime with automatic string conversion throws error.

Repro code

open System

let (isParsable: bool), (dt: DateTime) = System.DateTime.TryParse("2018-10-01T11:12:55.00Z")
let expected = System.DateTime(2018, 10, 1, 13, 12, 55)

printfn "isParsable: %A" isParsable

printfn "result: %A" dt // without this line, the code runs.

printfn "isEqual: %A" (dt = expected)

Expected and actual results

Expected results

Printing all information.

Actual results

With printfn "result: %A" dt the code throws:

isParsable: true
Traceback (most recent call last):
  File "C:\Users\Freym\Desktop\fable_test\test.py", line 29, in <module>
    to_console(printf("result: %A"))(dt)
  File "C:\Users\Freym\Desktop\fable_test\fable_modules\fable_library\string_.py", line 165, in _
    str_copy = format_once(str_copy, arg)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Freym\Desktop\fable_test\fable_modules\fable_library\string_.py", line 157, in format_once
    ret = _fs_format_regexp.sub(match, str2, count=1)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Freym\Desktop\fable_test\fable_modules\fable_library\string_.py", line 154, in match
    once: str = format_replacement(rep, flags, pad_length, precision, format)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Freym\Desktop\fable_test\fable_modules\fable_library\string_.py", line 110, in format_replacement
    rep = date_to_string(rep)
          ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Freym\Desktop\fable_test\fable_modules\fable_library\date.py", line 460, in to_string
    return date_to_string_with_offset(date, format)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Freym\Desktop\fable_test\fable_modules\fable_library\date.py", line 426, in date_to_string_with_offset
    raise NotImplementedError("date_to_string_with_offset")
NotImplementedError: date_to_string_with_offset

Related information

  • Fable version: dotnet fable --version: 4.19.2
  • Operating system: Win 11 Pro
@Freymaurer
Copy link
Author

Plus a minor issue with System.DateTimeOffset.TryParse().

I just checked and the following f# throws the error: TypeError: try_parse() missing 3 required positional arguments: 'unsigned', 'bitsize', and 'defValue'.

let str  = """2008-01-05 6:00:00"""

let is_parsable, dt_offset = DateTimeOffset.TryParse(str)

transpiled to

def _arrow2(__unit: None=None) -> tuple[bool, Any]:
    out_arg: Any = min_value()
    def _arrow0(__unit: None=None) -> Any:
        return out_arg

    def _arrow1(v: Any) -> None:
        nonlocal out_arg
        out_arg = v

    return (try_parse(str_1, FSharpRef(_arrow0, _arrow1)), out_arg)

# with

def try_parse(string: str, style: int, unsigned: bool, bitsize: int, defValue: FSharpRef[datetime]) -> bool:
    try:
        defValue.contents = parse(string)
        return True
    except Exception:
        return False

For try_parse the arguments style: int, unsigned: bool, bitsize: int are unused

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant