I'm trying to get the week number of a date using the System.Globalization.Calendar.GetWeekOfYear function (https://docs.microsoft.com/en-us/dotnet/api/system.globalization.calendar.getweekofyear?view=netcore-3.1)
The code below does not compile using the fable-compiler (2.13.0) while it does compile using dotnet build
The following code causes the error in the REPL:
open System.Globalization
open System
CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(DateTime(1,1,2020), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)
Expected: returns integer corresponding to week number of specified date.
Actual: throws the following error:
FABLE: Cannot resolve System.Globalization.CultureInfo.get_CurrentCulture
local fable-compiler version: 2.13.0
REPL fable-compiler version: 2.10.1
operating system: Windows 10 (error is reproducible in REPL)
Hello @stan-kroon,
Fable doesn't provide support for all the BCL API's and the "Globalization" API is one of them.
I don't think that support for it will be included in Fable.
The reason, is that we don't always have the equivalent available in native JavaScript and also it could be a lot of work to do and maintains.
Thanks for your response Maxime, makes sense!
Maybe related, there's a proposal to support CultureInfo #2126. It's not a priority at the moment, but of course anybody wanting to give it a try is more than welcome :)
@stan-kroon Also related :wink: you can install Fable.DateFunctions (along with its dependency date-fns) and then calculate which week it is like this
open System
open Fable.DateFunctions
let now = DateTime.Now
let currentWeekNumber = now.DifferenceInCalendarWeeks(now.StartOfYear())
At least, I think this will work :smile:
There is also DifferenceInCalendarISOWeeks extension method, maybe you can try that one
Thanks Zaid-Ajaj, that is exactly what I need!
Most helpful comment
@stan-kroon Also related :wink: you can install Fable.DateFunctions (along with its dependency
date-fns) and then calculate which week it is like thisAt least, I think this will work :smile:
There is also
DifferenceInCalendarISOWeeksextension method, maybe you can try that one