Fabric/Fluent UI Datepicker days of week are misaligned with calendar numerical date - fluent-ui

Fabric/Fluent UI Datepicker calendar numerical dates are misaligned with the actual days of the week. Screenshot to demonstrate:
^ as can be seen, the highlighted today date is marked September 17th, 2020, under the calendar's Friday column, but this is clearly wrong because September 17th, 2020 is a Thursday.
I have considered this might be due to an error in the actual Date() object, but that doesn't make sense because that should only cause the date to be wrong, the alignment of calendar numerical date to day of the week should never be misaligned like this, as that is simply wrong no matter what. September 17th, 2020 will always be a Thursday, and not a Friday, no matter what Date() object you input into the Datepicker.
Is this a bug with the Fabric/Fluent UI Datepicker? Is anyone else getting this behavior, or is there something I might have overlooked?
Many thanks in advance.

SOLVED
The problem was that Fluent UI accepts the shortDay strings in a certain order:
shortDays: ['S', 'M', 'T', 'W', 'T', 'F', 'S']
(see docs: https://developer.microsoft.com/en-us/fluentui#/controls/web/datepicker)
But because in my app I need to localize for different locales, I'm using Luxon to generate the day strings like so:
import { Info } from 'luxon';
shortDays: Info.weekdays('narrow', {locale: i18n.locale})
..and that outputs as
shortDays: ['M', 'T', 'W', 'T', 'F', 'S', 'S']
...which causes the strings to shift X_X (Fluent UI Datepicker reads 'M' as Sunday, 'T' as Monday, etc...)
Therefore, to solve it, I dropped this one line into my render method just before I return the HTML:
this.DayPickerStrings.shortDays.unshift(this.DayPickerStrings.shortDays.pop());
(yeah yeah I know, class components in React are outdated, but I didn't write this code originally, I'm just inheriting it)

Related

kotlin OffsetDateTime format of pattern

I am try to convert a offsetdatetime to a specific format, but i have a problem
OffsetDateTime.parse("2021-12-27T15:49:08Z")
.format(DateTimeFormatter.ofPattern("EEE dd MMM YYYY, h:mm:ss"))
and it print one year more
lun. 27 dic. 2022, 3:49:08
what is the reason?
thanks a lot
This is because you're specifying the pattern YYYY for the year.
According to the docs for java.time.format.DateTimeFormatter, a pattern of one or more Ys means ‘week-based year’.
That's different from the usual ‘year-of-era’, which you get from a pattern of one or more lower-case ys.
The difference is explained in this question. Basically, if the year starts in the middle of a week, it treats that entire week as falling either in the previous year or the following year.
The exact calculation will depend indirectly upon the locale, as that controls which day the week starts on. (I don't fully understand all the details, but I think it's mediated by the WeekFields class. However it works, it can cause the last few days of 2021 to be treated as part of 2022, as this question demonstrates.)
In any case, it looks like your real problem is using a week-based year number when you just want the normal calendar year! So, simply change your pattern to "EEE dd MMM yyyy, h:mm:ss", and you should get the expected result:
lun. 27 dic. 2021, 3:49:08

Print object properties using member function in Kotlin

I am really confused with the task I received from the Jetbrains Academy.
There is a calendar object which has day, month and year properties. Somebody has created a selectCurrentDay() member function that sets the object's properties to the current day. There is no need to type the date manually anymore because we have the selectCurrentDay() function!
Initially, the calendar shows a random date. Implement the current date printing: select it and print the day, the month and the year split by a space.
Output example:
21 12 2021
What i did was:
val calendar = createCalendar()
calendar.selectCurrentDay()
print("{$calendar.day} ${calendar.month} ${calendar.year}")
However my answer is rejected. What do they want me to implement?
print("${calendar.day} ${calendar.month} ${calendar.year}")

ms-access built in function Month(number)

I Have been playing with variations of the Month... function in access query builder. I am having trouble building a date value from an expression. I am looking to create my own date that will be behind the scenes to perform some filtering and other tasks. My problem is that I cant seem to get the Month(number) function to do what I think it should be doing. Here is a summary of what I am looking for.
5/31/2012
Through something like this
DateSerial(Year(Date()),Month(5),Day(31))
Also
DateSerial(Year(Date()),Month("5"),Day("31"))
When I try these as an experssion the return is
1/30/2012
Im sure I am misunderstanding the structure. Please educate me.
DateSerial requires three integers, year, month, day:
DateSerial(1992,5,2)
02/05/1992 ''Euro locale
Year(Date()) returns an integer, so you can substitute:
DateSerial(Year(Date()),5,31)
Interestingly, the zeroth day is the last day of the previous month:
DateSerial(2012,12,0)=30/11/2012
-- http://office.microsoft.com/en-ie/access-help/HV080206953.aspx
As an aside, do not forget that all dates are numbers.
Month(5) will equal 1, but Month(41263)=12 !
Also
?month(100)
4
?Year(100)
1900

Is there an easy way with NSDateFormatter to get "Today", "Tomorrow","Friday" style dates?

I'm working on setting up NSDateFormatter to explain the date, and I'd like something short but more intuitive than 15/07/10. I think I've seen some formats that will say simply "Today" or "Tomorrow" or the day of the week for subsequent days of the same week. Is there a simple apple-approved way to get this type of date?
Thanks.
If you're targeting iOS 4 or later, you can call [yourFormatter setDoesRelativeDateFormatting:YES]. Otherwise, you'll most likely need a custom subclass. As for days of the week, what jer said.
Ensure you set up your locale with the NSDateFormatter appropriately, and then ask for the weekdaySymbols. This will return an array with the days of the week in the locale you specify.

Change UIDatePicker from 12 hour clock to 24 hour clock and back

I'm sorry to make my first question here a bit of a simple one -- I've spent a day reading the NSLocale and NSCalendar class descriptions but I couldn't see if this was possible.
I have a UIDatePicker in the UIDatePickerModeDateAndTime mode. It is currently displaying date and time according to the user's locale, which is the default behavior.
I would like to be able to offer the option to show the UIDatePicker in either 12-hour or 24-hour time format. Detecting which time format the user is currently using isn't a problem, but I'm not clear on how to change just the time format of UIDatePicker without entirely throwing out the user's locale settings (since the picker also displays the localized days of the week and months). UIDatePicker supports setting its locale and setting its calendar.
So, question one is whether this is something I should be trying to do via NSLocale or NSCalendar, and question two is if anyone can recommend a way to isolate the time format without throwing out the rest of the user's locale settings.
Thanks for any suggestions.
This is not the answer you are looking for, but in Cocoa you could create an NSDateFormatter and attach it to an NSDatePicker (which is an NSControl) using setFormatter. Unfortunately the equivalent iPhone class (UIControl) does not support this yet. I raised a bug with Apple about it and this is a known issue, although they wouldn't tell me if/when they plan to fix/enhance it.
OK, after reading the last two years' worth of others asking the same question here, it seems that there is no way to do this since the UIDatePicker uses the user's country setting instead of the user's locale setting, and that can't be overridden programmatically. I filed a bug.
I have solved this problem by using the user input of AM/PM by initializing another variable as a string of either AM or PM based upon the 12 hour format. The new hour in 24 hour format is put into NSCalendar. To wit:
var hra = 1//ENTER INITIAL HOUR (HH)
var dna = "PM"//ENTER "AM" OR "PM"
if hra <= 12 && dna == "PM"{
hra = hra + 12
}
The variable hra now takes the value of the 24 hour format.