Add TimeZone management in meeting scheduling/editing

This commit is contained in:
QuentinArguillere 2024-08-13 09:52:19 +02:00
parent 6c072aafa0
commit 3588d97116
4 changed files with 56 additions and 26 deletions

View file

@ -214,7 +214,7 @@ struct MeetingFragment: View {
.foregroundStyle(Color.grayMain2c800)
.frame(width: 24, height: 24)
.padding(.leading, 15)
Text("TODO : timezone")
Text(meetingViewModel.currentTimeZone.formattedString())
.default_text_style(styleSize: 14)
Spacer()
}

View file

@ -66,7 +66,7 @@ struct MeetingsFragment: View {
.padding(.top, 5)
.default_text_style_500(styleSize: 15)
}
Text(model.model!.time)
Text(model.model!.time) // this time string is formatted for the current timezone, we use the selected timezone only when displaying details
.default_text_style_500(styleSize: 15)
}
}

View file

@ -192,33 +192,49 @@ struct ScheduleMeetingFragment: View {
.foregroundStyle(Color.grayMain2c800)
.frame(width: 24, height: 24)
.padding(.leading, 15)
Text("TODO : timezone")
Text("Time Zone:")
.fontWeight(.bold)
.padding(.leading, 5)
.default_text_style_500(styleSize: 16)
Picker(selection: $meetingViewModel.selectedTimezoneIdx, label: EmptyView() ) {
ForEach(0..<meetingViewModel.knownTimezones.count, id: \.self) { idx in
Text(TimeZone.init(identifier: meetingViewModel.knownTimezones[idx])?.formattedString() ?? "Unknown timezone").tag(idx)
}
}
.onReceive(meetingViewModel.$selectedTimezoneIdx) { value in
if let timeZone = TimeZone.init(identifier: meetingViewModel.knownTimezones[value]) {
meetingViewModel.updateTimezone(timeZone: timeZone)
} else {
Log.error("Could not find matching timezone for index \(value)")
}
}
.pickerStyle(MenuPickerStyle())
.tint(Color.grayMain2c800)
.padding(.leading, -10)
Spacer()
}
/*
HStack(alignment: .center, spacing: 10) {
Image("arrow-clockwise")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.grayMain2c800)
.frame(width: 24, height: 24)
.padding(.leading, 15)
//Picker(selection:, label:("))
Text("TODO : repeat")
.fontWeight(.bold)
.padding(.leading, 5)
.default_text_style_500(styleSize: 16)
Spacer()
}
*/
*/
Rectangle()
.foregroundStyle(.clear)
.frame(height: 1)
.background(Color.gray200)
HStack(alignment: .top, spacing: 8) {
HStack(alignment: .top, spacing: 10) {
Image("note")
.renderingMode(.template)
.resizable()

View file

@ -33,13 +33,16 @@ class MeetingViewModel: ObservableObject {
@Published var fromTime: String = ""
@Published var toDateStr: String = ""
@Published var toTime: String = ""
@Published var timezone: String = ""
@Published var sendInvitations: Bool = true
@Published var participants: [SelectedAddressModel] = []
@Published var operationInProgress: Bool = false
@Published var conferenceCreatedEvent: Bool = false
@Published var conferenceUri: String = ""
@Published var selectedTimezoneIdx = 0
var currentTimeZone = TimeZone.current
var knownTimezones : [String] = []
var conferenceScheduler: ConferenceScheduler?
private var mSchedulerSubscriptions = Set<AnyCancellable?>()
var conferenceInfoToEdit: ConferenceInfo?
@ -52,9 +55,21 @@ class MeetingViewModel: ObservableObject {
init() {
fromDate = Calendar.current.date(byAdding: .hour, value: 1, to: Date.now)!
toDate = Calendar.current.date(byAdding: .hour, value: 2, to: Date.now)!
var tzIds = TimeZone.knownTimeZoneIdentifiers
tzIds.sort(by: {
let gmtOffset0 = TimeZone(identifier: $0)!.secondsFromGMT()
let gmtOffset1 = TimeZone(identifier: $1)!.secondsFromGMT()
if gmtOffset0 == gmtOffset1 {
return $0 < $1 // sort by name if same GMT offset
} else {
return gmtOffset0 < gmtOffset1
}
})
knownTimezones = tzIds
selectedTimezoneIdx = knownTimezones.firstIndex(where: {$0 == currentTimeZone.identifier}) ?? 0
computeDateLabels()
computeTimeLabels()
updateTimezone()
}
func resetViewModelData() {
@ -63,7 +78,6 @@ class MeetingViewModel: ObservableObject {
subject = ""
description = ""
allDayMeeting = false
timezone = ""
sendInvitations = true
participants = []
operationInProgress = false
@ -73,26 +87,32 @@ class MeetingViewModel: ObservableObject {
toDate = Calendar.current.date(byAdding: .hour, value: 2, to: Date.now)!
computeDateLabels()
computeTimeLabels()
updateTimezone()
}
func updateTimezone(timeZone: TimeZone) {
currentTimeZone = timeZone
computeDateLabels()
computeTimeLabels()
}
func computeDateLabels() {
var day = fromDate.formatted(Date.FormatStyle().weekday(.wide))
var dayNumber = fromDate.formatted(Date.FormatStyle().day(.twoDigits))
var month = fromDate.formatted(Date.FormatStyle().month(.wide))
fromDateStr = "\(day) \(dayNumber), \(month)"
Log.info("\(MeetingViewModel.TAG) computed start date is \(fromDateStr)")
var weekDayFormat = Date.FormatStyle().weekday(.wide)
weekDayFormat.timeZone = currentTimeZone
var dayNumberFormat = Date.FormatStyle().day(.twoDigits)
dayNumberFormat.timeZone = currentTimeZone
var monthFormat = Date.FormatStyle().month(.wide)
monthFormat.timeZone = currentTimeZone
day = toDate.formatted(Date.FormatStyle().weekday(.wide))
dayNumber = toDate.formatted(Date.FormatStyle().day(.twoDigits))
month = toDate.formatted(Date.FormatStyle().month(.wide))
toDateStr = "\(day) \(dayNumber), \(month)"
fromDateStr = "\(fromDate.formatted(weekDayFormat)) \(fromDate.formatted(dayNumberFormat)), \(fromDate.formatted(monthFormat))"
Log.info("\(MeetingViewModel.TAG) computed start date is \(fromDateStr)")
toDateStr = "\(toDate.formatted(weekDayFormat)) \(toDate.formatted(dayNumberFormat)), \(toDate.formatted(monthFormat))"
Log.info("\(MeetingViewModel.TAG)) computed end date is \(toDateStr)")
}
func computeTimeLabels() {
let formatter = DateFormatter()
formatter.dateFormat = Locale.current.identifier == "fr_FR" ? "HH:mm" : "h:mm a"
formatter.timeZone = currentTimeZone
fromTime = formatter.string(from: fromDate)
toTime = formatter.string(from: toDate)
}
@ -105,10 +125,6 @@ class MeetingViewModel: ObservableObject {
return "\(day). \(dayNumber) \(month) \(year) | \(allDayMeeting ? "All day" : "\(fromTime) - \(toTime)")"
}
private func updateTimezone() {
// TODO
}
func addParticipants(participantsToAdd: [SelectedAddressModel]) {
var list = participants
for selectedAddr in participantsToAdd {
@ -300,7 +316,6 @@ class MeetingViewModel: ObservableObject {
self.conferenceUri = meeting.confInfo.uri?.asStringUriOnly() ?? ""
self.computeDateLabels()
self.computeTimeLabels()
self.updateTimezone()
self.displayedMeeting = meeting
}
}
@ -334,7 +349,6 @@ class MeetingViewModel: ObservableObject {
self.isBroadcastSelected = false // TODO FIXME
self.computeDateLabels()
self.computeTimeLabels()
self.updateTimezone()
//self.participants = list
}