WidgetKit: Refresh data based on a specific time?

Hi,

Is it possible to dynamically update a Widget / show a View based on a specific time?
For example, something like the following:


func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [SimpleEntry] = []
Code Block
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
let currentDate = Date()
// Get specific date / time to update then compare it to system's curren time.
var components = DateComponents()
components.hour = 12
components.month = 0
let midnight = Calendar.current.date(from: components)


if midnight == currentDate {
Code Block
let entry = SimpleEntry(date: Date(), text: "", configuration: ConfigurationIntent())
entries.append(entry)
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
} else {
for hourOffset in 0 ..< 6 {
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
let entry = SimpleEntry(date: entryDate, text: update, configuration: ConfigurationIntent())
entries.append(entry)
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
}
}


Thanks,
WidgetKit: Refresh data based on a specific time?
 
 
Q