mawaqit / android-tv-app

Prayer times App for Android TV
https://mawaqit.net
Other
34 stars 15 forks source link

refactor: AppDate for Improved Debug Time Flexibility #1076

Closed YassinNouh21 closed 3 months ago

YassinNouh21 commented 3 months ago

๐Ÿ“ Summary

This PR introduces improvements to the handling of debug time in the application, making it easier to test and debug time-related features.

This PR is for issue

1075

Description

The changes in this PR refactor the way debug time is calculated and used within the application. Previously, a static difference was used to simulate time changes for debugging. This approach was less flexible and could lead to confusion during development. The new implementation introduces _initialRealTime and _initialDebugTime, along with a computed _timeDifference that allows for more intuitive and manageable debugging of time-dependent features. This change aims to facilitate easier testing and development by providing a clear and adjustable method for simulating different times within the app.

Tests

๐Ÿงช Use case 1

๐Ÿ’ฌ Description: Testing the functionality of the debug time adjustment feature.

  1. Ensure the application is in debug mode.
  2. Observe the application's behavior at the simulated debug time.
  3. Adjust _initialDebugTime to a different time.
  4. Verify that the application now reflects the newly adjusted time.

๐Ÿ“ท Screenshots or GIFs (if applicable):

image

Checklist:

YassinNouh21 commented 3 months ago

Please move the initialization of _initialRealTime,_initialDebugTime & _timeDifference to the now() method itself. This way, the time difference will be recalculated every time without needing to restart the app to see the changes.

do you mean this.

static DateTime now() {
    final DateTime _initialRealTime = DateTime.now();
    final DateTime _initialDebugTime = DateTime(
        _initialRealTime.year,
        _initialRealTime.month,
        _initialRealTime.day,
        13,
        5
    );
    final _timeDifference = _initialDebugTime.difference(_initialRealTime);
    if (kDebugMode) {
      return DateTime.now().add(_timeDifference);
    } else {
      return FeatureManagerProvider.featureManager
          .isFeatureEnabled("timezone_shift") &&
          _timeManager.deviceModel == "MAWABOX" &&
          _timeManager.isLauncherInstalled
          ? DateTime.now().add(Duration(
          hours: _timeManager.shift, minutes: _timeManager.shiftInMinutes))
          : DateTime.now();
    }
  }