SwiftUI DatePicker Month Display Conundrum - swiftui

Help! Depending on the selected date, the displayed date for a Swift DatePicker with CompactDatePickerStyle shows the month ('Mar'):
Or shows the month number ('3'):
I want all dates to display with the month name (abbreviated or full).
Here's the complete application in Xcode version 12.4:
struct ContentView: View {
#State var date: Date = Date()
var body: some View {
DatePicker("Date", selection: $date)
.datePickerStyle(CompactDatePickerStyle())
.padding()
}
}

Related

DatePicker(UIDatePicker) date format

Is there a way to set the date format of the DatePicker (UIDatePicker)?
You can set the Locale and that would result in changing of the date format, but what if you would like to set a en_CA locale but instead of the default Jan 3, 2022 format you would want 2022-01-03.
My setup is in SwiftUI, but I guess the same approach would likely work for UIKit/SwiftUI.
DatePicker(
"My date",
selection: $date,
in: ...Date(),
displayedComponents: [.date]
)
.frame(alignment: .leading)
.labelsHidden()
.id(date) // hack, see https://stackoverflow.com/a/68120390/429763
.environment(\.locale, Locale.init(identifier: "en_CA"))
.onChange(of: date) { date in
Log("On change date: \(date)")
}

Why does my dax filter show empty values that are not in the filter instead of hiding them?

I'm trying to filter values from a Column chart :
The chart is like this :
The lightgreen column chart value is from a Measure : Selection Date
And I use a Slicer to filter values like this :
The values are from a table Parametres
So here is my Selection_Date measure :
Selection Date = [DateFilter]
DateFilter is an other measure that choose how to filter the values (based on the slicer's selection).
DateFilter =
var _today = TODAY()
var _month = MONTH(_today)
var _year = YEAR(_today)
var _last_30_days = _today - 30
return SWITCH(SELECTEDVALUE(Parametres[Selection_date]),
"Last30Days", CALCULATE( SUM(v_revenues[qty]), FILTER(v_dates, v_dates[Date] > _last_30_days )),
"MonthToDate", CALCULATE(SUM(v_revenues[qty]), FILTER(v_dates, v_dates[actual_month] = 1)),
"YearToDate", CALCULATE(SUM(v_revenues[qty]), FILTER(v_dates, v_dates[actual_year] = 1))
)
This measure works but I still have one problem. The filter is ok but when I filter a values (example month to date) all the value that are not in the selection (all the values that are not november 2021) are still visible but they are empty :
So here is my question :
How can I add the values that are not in the selection ? How can I filter so it only display the values that are in the checked in the slicer ?
Per example, for Date to Month I want only this to be displayed :
I resolved it by using a Bookmark and then I associated a button to this Bookmark !

How is the Trend measure being calculated in the Power BI Usage Metrics reports?

The link https://learn.microsoft.com/en-us/power-bi/collaborate-share/service-modern-usage-metrics says "The view trend reflects view count changes over time. It compares the first half of the selected time period with the second half." but how would I do this with a measure?
View Trend measure is available in the dataset in modern workspace usage metric. However it is not available in the classic workspace usage metric or the old usage metrics report. This DAX is what I have written and have been using...
Trend =
VAR StartDate = MIN(Views[Date])
VAR EndDate = MAX(Views[Date])
VAR PeriodHalfDaysCount = INT((MAX(Views[Date])-MIN(Views[Date]))/2)
VAR MidDate = StartDate+PeriodHalfDaysCount
VAR FirstHalfView = CALCULATE([ViewsCount], DATESBETWEEN(Views[Date],StartDate,MidDate))
VAR SecondHalfView = CALCULATE([ViewsCount], `enter code here`DATESBETWEEN(Views[Date],MidDate+1,Enddate))
RETURN DIVIDE (SecondHalfView-FirstHalfView,FirstHalfView)

Week number of year becomes 1 during the last week of the year

In this case, the output becomes 1 instead of 53 for the last week of the year, how can this be changed to show the proper week numbers?
struct ContentView: View {
#State var date = Date()
var weekFormatter: DateFormatter{
let formatter = DateFormatter()
formatter.dateFormat = "w"
return formatter
}
var body: some View {
VStack{
DatePicker(selection: $date, displayedComponents: .date, label: {Text("Bing")})
Text("\(date, formatter: weekFormatter)")
}
}
}
The meaning of the w character in the date format is described by Unicode Technical Standard #35 Part 4 ยง8.4. As of version 37, it says this:
8.4 Week of Year
Values calculated for the Week of Year field range from 1 to 53 for the Gregorian calendar (they may have different ranges for other calendars). Week 1 for a year is the first week that contains at least the specified minimum number of days from that year. Weeks between week 1 of one year and week 1 of the following year are numbered sequentially from 2 to 52 or 53 (if needed). For example, January 1, 1998 was a Thursday. If the first day of the week is MONDAY and the minimum days in a week is 4 (these are the values reflecting ISO 8601 and many national standards), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. However, if the first day of the week is SUNDAY, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998. The first three days of 1998 are then part of week 53 of 1997.
Values are similarly calculated for the Week of Month.
So, if you want to change the way the weeks are numbered, you need to change the first day of the week, or the minimum days in a week, or both. You do that by creating a Calendar, setting the firstWeekday and minimumDaysInFirstWeek properties, and then assigning the Calendar to your DateFormatter's calendar property:
var calendar = Calendar(identifier: .gregorian)
calendar.firstWeekday = ...
calendar.minimumDaysInFirstWeek = ...
let formatter = DateFormatter()
formatter.calendar = calendar
formatter.dateFormat = "w"

How to set the first date of current week to Wednesday in Swift?

How to set the first date of the week to Wednesday and show the first and last date of week on yellow bar? Because the schedule will update every Wednesday.
Please check this might help :
var calendar = Calendar.current
calendar.firstWeekday = 4
let startOfWeek = calendar.date(from: calendar.dateComponents([.yearForWeekOfYear, .weekOfYear], from: Date()))!
let endOfWeek = calendar.date(byAdding: .day, value: 6, to: startOfWeek)!
print(startOfWeek)
print(endOfWeek)