Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latitute bigger than 75 throws an exception #61

Open
MuhammadSwa opened this issue Apr 25, 2024 · 6 comments
Open

Latitute bigger than 75 throws an exception #61

MuhammadSwa opened this issue Apr 25, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@MuhammadSwa
Copy link

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

  • when running this function you get the error.
PrayerTimes? getPrayersTimes() {
  const double latitude = 76;
  const double longitude = 179;

  final myCoordinates = Coordinates(latitude, longitude,validate: true);
  final params = CalculationMethod.egyptian.getParameters();
  params.madhab = Madhab.shafi;
  final PrayerTimes prayerTimes = PrayerTimes.today(myCoordinates, params);

  return prayerTimes;
}

Expected behavior
Latitude maxium value should be 90 not 75

Environment(please complete the following information):

  • Dart Language Version: [e.g. Dart 3.3.4]
  • Adhan-Dart Version: [2.0.0+1]
@MuhammadSwa MuhammadSwa added the bug Something isn't working label Apr 25, 2024
@moha-b
Copy link

moha-b commented Apr 26, 2024

The issue description is unclear. Can you please provide more details or clarify what you meant?

@MuhammadSwa
Copy link
Author

  • This is a sample program to produce the error with the given package version
void main() {
  final p1 = getPrayersTimes(latitude: 74, longitude: 179); // this works as expected
  final p2 = getPrayersTimes(latitude: 74, longitude: -179); // this works as expected/

  final p3 = getPrayersTimes(latitude: 75, longitude: 179); //this throws an error
}

PrayerTimes? getPrayersTimes({required double latitude, required double longitude}) {
  final myCoordinates = Coordinates(latitude, longitude,validate: true);
  final params = CalculationMethod.egyptian.getParameters();
  params.madhab = Madhab.shafi;
  return  PrayerTimes.today(myCoordinates, params);
}
  • In class Coordinates, any latitude between -90 and 90 is accepted. Any longitude between -180 and 180 should be accepted.
  Coordinates(this.latitude, this.longitude, {bool validate = false}) {
    if (validate) {
      if (!(latitude.isFinite && latitude.abs() <= 90)) {
        throw ArgumentError(
            'Invalid Latitude supplied, Latitude must be a number between -90 and 90');
      }

      if (!(longitude.isFinite && longitude.abs() <= 180)) {
        throw ArgumentError(
            'Invalid longitude supplied, Longitude must a number between -180 and 180');
      }
    }
  }
  • Longitude values always works as expected, any value is valid between -180 and 180. see p1 and p2.
  • But if you pass latitude values >= 75, the Coordinates class validates it correctly but somewhere else in the code is throws an error like this one below
Unhandled exception:
Invalid argument(s): value should not be infinite or NaN
#0      TimeComponents.fromDouble (package:adhan/src/data/time_components.dart:12:7)
#1      new PrayerTimes._ (package:adhan/src/prayer_times.dart:142:24)
#2      new PrayerTimes.today (package:adhan/src/prayer_times.dart:68:24)
#3      getPrayersTimes (package:test_app/main.dart:14:47)
#4      main (package:test_app/main.dart:7:14)
#5      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#6      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
  • if i failed to demonstrate the problem, please let me know exactly what's unclear.

@moha-b
Copy link

moha-b commented Apr 29, 2024

May I ask why you're using static lat and lon? It should be dynamic and come from packages like geolocator

@MuhammadSwa
Copy link
Author

I'm actually doing that this is just a simplified version of my application to demonstrate the problem. Did you run the code? Is the problem reproducable?

@moha-b
Copy link

moha-b commented Apr 30, 2024

I have executed the code, and it generated the same error, but it seems to be identifying it as NaN for some reason. However, I am not entirely sure what is causing the issue. It could be possible that this particular location is causing the problem because it's an ocean, which might be a factor. Nonetheless, I'm uncertain about the root cause of the problem.

@MuhammadSwa
Copy link
Author

Okay thanks for your effort

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants