How to detect which event fired applicationSignificantTimeChange - iphone

How to detect which event (arrival of midnight or an update of the time by a carrier or the change to daylight savings time) has fired the applicationSignificantTimeChange method ?

You can cheat in this case:
check hour and minute in applicationSignificantTimeChange, if hour and minute is zero, it mean midnight or using a server time for validate

Related

Flutter stopwatch running slower than expected

My stopwatch is running 0.5x slower than actual time
(e.g. while the real time is 1 minute, the stopwatch shows ~34 seconds).
Here is the Provider code:
class TimerState extends ChangeNotifier {
  late String _stringTimer;
  late Duration _duration;
  Timer? _timer;
  TimerState() {
    _stringTimer = '00:00.00';
    _duration = const Duration();
  }
  String get get => _stringTimer;
  void start() {
    _timer = Timer.periodic(const Duration(milliseconds: 1), (_) => _addTime());
  }
  void _addTime() {
    _duration = Duration(milliseconds: _duration.inMilliseconds + 1);
    _formattedTimer();
  }
  void _formattedTimer() {
    String twoDigits(int n) => n.toString().padLeft(2, '0');
    final milliseconds = twoDigits((_duration.inMilliseconds.remainder(1000) / 10).floor());
    final seconds = twoDigits(_duration.inSeconds.remainder(60));
    final minutes = twoDigits(_duration.inMinutes.remainder(60));
    _stringTimer = '$minutes:$seconds.$milliseconds';
    notifyListeners();
  }
}
Your approach adds the timer interval (1ms) on each timer event. That is a bad approach because it assumes that your timer fires exactly on every millisecond with no room for error. You also will lose time if any timer events are missed (which might happen if you ever do work that takes longer than 1ms). Error will accumulate.
Also note that 1ms is very short. Redrawing your widget every millisecond would be updating it at a rate of 1000 frames per second.
A much better approach would be to record the start time and, on each timer event, compute the difference from DateTime.now() to the start time (e.g. var elapsed = DateTime.now().difference(startTime);). That will prevent error from accumulating. Better yet, use a Stopwatch object which does that for you.
You also should pick a more reasonable timer interval; picking a rate faster than your screen's refresh rate is wasteful.

How to get Azure Data Factory Tumbling Window Trigger to work with Daylight Savings Time

I have some tumbling window triggers that are set to run at specific intervals 6 hours apart. They need to run at a designated time (think 5am and 11am, and so on) I have them set up so that they are self-dependent and dependent on a connection check trigger.
The problem arises when daylight savings comes around. Tumbling window triggers only work in UTC and when the clock changes in our time zone, the times they are triggered change by an hour (forward or back depending on the time of year). This causes data to be late to its destination and I am forced to manually deploy new triggers around daylight savings time.
I am wondering if there is a better way to work around daylight savings time as Tumbling Window Triggers do not support any time zone other than UTC and deploying new triggers every time is not an effective solution.
Not sure if I understand your requirement, it is actually different between 6 hours apart and setting scheduled triggers for 2 designated times which are 6 hours apart.
If you want to schedule the job for every 6 hours, the timezone should have no impact since the trigger should always trigger every 6 hours. This is the correct use case for tumbling window trigger.
If you want to schedule for designated times, you should go for scheduled trigger, which supports for timezones. For catering daylight saving time, you can simply select the timezone you want, ADF will auto adjust according to daylight saving time as specified in the UI.

Can interarrival time be used with anylogic schedule block?

I'm trying to model a production sequence in anylogic where orders should come in with an interarrival time of normal(8,105) seconds. These orders should come in every week day between 11 am and 2 pm (3 hour window).
I tried to implement this with the Schedule block in anylogic but this only allows me to define a rate per hour. Is there a way to do this with interarrival time?
Also the agents that arrive at 1:59 pm should also be processed even if it takes until after 2 pm. Is there a way to calculate the mean working time per day (the time from the generation of the first agent by the source block until the last generated agent enters the sink block)?
Thank you all in advance!
I would use the getHour() function and dispose of the agents if hour is not between 11 and 14. And inside the source you don't need to do anything special. If it even arrives at 11.59 pm it will be processed.

Calculating the timezone offset of a future date knowing only the current offset

So 3rd March 2021 in US Eastern timezone it is 5 hours from UTC, and the offset is 300 minutes.
For a future date, 01-Apr-2021 the clocks will change and the offset will be different.
But if the code only knows the offset and doesnt know which timezone the original offset came from, am I correct that it would be impossible to determine the future dates timezone offset.
Yes, you are correct. There are many other time zones that also use the UTC-5 offset. Some of them do not switch for DST at all. Some of them switch for DST at a later or earlier date. Some of them, UTC-5 is the DST offset and thus they switch back to UTC-6 instead of to UTC-4.
To have any understanding of how an offset will change over time, you need to identify the time zone, not just the offset. Preferably, you would use an IANA time zone identifiers, such as "America/New_York".
See the timezone tag wiki, in particular the section titled "Time Zone != Offset".
Additionally, note that even with a time zone identified, future offsets are always just an estimate. If a government changes their mind about what the time zone or DST rules are between the date your time zone data was last updated and the date such a change goes into effect, then the offset you determined might be incorrect under the new rules. There's not much you can do about that, other than to not speculate too far into the future, and to urge governments not to make short-notice changes.

Triggering UNUserNotification Trigger with Changing Repeat Interval

I've gone through all of Apple's Documentation on the new User Notification framework and I am officially stumped.
I need to set up a UNNotificationRequest to trigger after X days. This can be easily accomplished with the UNTimeIntervalNotificationTrigger. However, the problem is that I need this notification to then repeat every Y days. Where Y is not necessarily equal to X.
I originally thought I could simply schedule a second UNNotificationRequest that repeats on a time interval of Y, but then it would either fire before that first X date is passed or it would not fire on the correct intervals.
For example, if I schedule a notification for 3 days from now and then want that notification to repeat every day after it fires, how would I do this without setting up my own scheduling system to wake the app up in the background and check if the it is time to schedule a second UNNotificationRequest?