Zaid-Ajaj / the-elmish-book

A practical guide to building modern and reliable web applications in F# from first principles
https://zaid-ajaj.github.io/the-elmish-book
Other
336 stars 49 forks source link

Problem with parsing to DateTime from int representation of a date. #175

Closed ostapsivko closed 2 years ago

ostapsivko commented 2 years ago

Hello Zaid,

I was following your book and doing exercises on Hackernews site. When I tried to implement a feature to show how long ago a post was made I've installed date-fns package and Fable.DateFunctions as well.

However when trying to parse an int "time" field that I get as a part of a response from Hackernews API, my app starts crashing. The error I am getting ("3 arguments required, but only 1 present") leads me to thinking that somehow wrong function is used to parse the time that I've provided, even though I've specified the type and source compiles without any problems.

1

I was trying to use active patterns to parse the difference in time between DateTime.Now and "time" value. Do you know if the issue is that I'm trying to use active patterns? Or maybe it is something unrelated?

Do you need anything else from me to help identify the root of the problem? Let me know please and thank you in advance.

P.S thanks a lot for your book, for me it is a great source of knowledge as for someone who only recently started to get to know about FP in general and F# in particular.

MangelMaxime commented 2 years ago

Hello @ostapsivko ,

it would be useful if you could provide a minimal reproduction code of some sort.

ostapsivko commented 2 years ago

Hello @MangelMaxime Thanks for the response!

I've used pastebin to provide the code I'm having troubles with: https://pastebin.com/n1PSmQuz.

The active pattern starts on the line 171. Line 172 contains a call to DateTime.Parse which is supposed to parse an integer I'm providing.

Here's my solution structure: image

Here's package.json: image

I've tried to recreate a project from scratch and it's still happening. Any advice would be appreciated!

ostapsivko commented 2 years ago

I was able to get to the bottom of it I think.

Date-fns is using different API after 2.0.0 update:

image

@Zaid-Ajaj do you think I should open an issue in Fable.DateFunctions that relates to that or is it unnecessary?

Thanks in advance