Skip to content

Fix 2 digits years datetime#1127

Merged
alfonsogarciacaro merged 1 commit intomasterfrom
fix_2_digits_year_date
Sep 2, 2017
Merged

Fix 2 digits years datetime#1127
alfonsogarciacaro merged 1 commit intomasterfrom
fix_2_digits_year_date

Conversation

@MangelMaxime
Copy link
Copy Markdown
Member

In JavaScript date have this behavior:

If a year between 0 and 99 is specified, the method converts the year to a year in the 20th century (1900 + year); for example, if you specify 95, the year 1995 is used.

In F#, if you set a datetime via Datetime(1, 1, 1) you want the year 1 and not 1901.

@alfonsogarciacaro
Copy link
Copy Markdown
Member

Good catch, thanks! 📅

@alfonsogarciacaro alfonsogarciacaro merged commit 3297b6b into master Sep 2, 2017
@ncave
Copy link
Copy Markdown
Collaborator

ncave commented Sep 8, 2017

The second test is always failing for me locally for some reason, not sure why:

  1268 passing (5s)
  1 failing

  1) DateTime DateTime UTC from Year 1 to 99 works:

      Error: Expected: 1 - Actual: 2

@MangelMaxime
Copy link
Copy Markdown
Member Author

That's really strange... Because it's the year and we use UTC so there no timezone taken into account here...

What is the result you get when running the same code in your fsi ?

@ncave
Copy link
Copy Markdown
Collaborator

ncave commented Sep 8, 2017

@MangelMaxime The dotnet version prints 1, but the javascript version (i.e. fable-core/Date/year) consistently prints 2.

@ncave
Copy link
Copy Markdown
Collaborator

ncave commented Sep 8, 2017

@MangelMaxime If that helps, if I change the DateTimeKind to Local, it prints 1 for the year. Or if I change the month or the day to 2 or more, it prints 1 for the year. Confusing, I know.

@MangelMaxime
Copy link
Copy Markdown
Member Author

@ncave So this have something to do with the edge case.

The date used for the tests is 0001-01-01 (1 January of year 0001).

Can you please tell me the result of each line of this code on your machine ? (It's JavaScript code) I am trying to break down the code step by step to understand the situation.

var d = new Date(Date.UTC(1, 0, 1, 0, 0, 0))
d.toString()
d.setFullYear(1)
d.toString()
d.getYear()
d.getUTCFullYear()

@ncave
Copy link
Copy Markdown
Collaborator

ncave commented Sep 8, 2017

@MangelMaxime Fixed in #1139.

@MangelMaxime
Copy link
Copy Markdown
Member Author

Ah thanks :)

I love how setFullYear takes month and day too... as argument.

@alfonsogarciacaro alfonsogarciacaro deleted the fix_2_digits_year_date branch November 30, 2017 20:36
github-actions bot added a commit that referenced this pull request Apr 2, 2026
…patterns

- Replace unsafe `.Value` on option types with safe pattern matching
  in Python/Replacements.fs (#1203) and Rust/Fable2Rust.fs (#1126, #1127)
- Add [<return: Struct>] to partial active patterns in Dart/Fable2Dart.fs
  (#1105, #1106), Dart/Replacements.fs (#1177), and Rust/Fable2Rust.fs
  (#1115, #1116, #1117, #1118, #1119, #1120, #1121, #1122, #1123, #1124)
  to reduce heap allocations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

3 participants