irongut / EDlib

A .Net Standard library for creating companion apps for the game Elite Dangerous by Frontier Developments.
MIT License
4 stars 0 forks source link

GalNet broken with some Arabic calendars #64

Closed irongut closed 3 years ago

irongut commented 3 years ago

Bug Report

GalNet News does not work with Arabic, Saudi Arabia (ar_sa) calendar.

NewsArticleConverter.SetProperty (Newtonsoft.Json.JsonReader reader, EDlib.GalNet.NewsArticle item)
System.FormatException: String was not recognized as a valid DateTime.

App Center Issue 1550929719

Stack Trace

System    DateTimeParse.Parse (System.ReadOnlySpan`1[T] s, System.Globalization.DateTimeFormatInfo dtfi, System.Globalization.DateTimeStyles styles)
System    DateTime.Parse (System.String s, System.IFormatProvider provider)
System    Convert.ToDateTime (System.String value, System.IFormatProvider provider)
System.String.System    IConvertible.ToDateTime (System.IFormatProvider provider)
System    Convert.ToDateTime (System.Object value)
EDlib.GalNet    NewsArticleConverter.SetProperty (Newtonsoft.Json.JsonReader reader, EDlib.GalNet.NewsArticle item)
EDlib.GalNet    NewsArticleConverter.ReadJson (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Object existingValue, Newtonsoft.Json.JsonSerializer serializer)
Newtonsoft.Json.Serialization    JsonSerializerInternalReader.DeserializeConvertable (Newtonsoft.Json.JsonConverter converter, Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Object existingValue)
Newtonsoft.Json.Serialization    JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent)
Newtonsoft.Json    JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType)
Newtonsoft.Json    JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType)
Newtonsoft.Json    JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings)
Newtonsoft.Json    JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonConverter[] converters)
Newtonsoft.Json    JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonConverter[] converters)
EDlib.GalNet    GalNetService+<>c__DisplayClass8_0.<GetData>b__0 ()
System.Threading.Tasks    Task.InnerInvoke ()
System.Threading.Tasks    Task.Execute ()
EDlib.GalNet    GalNetService.GetData (System.Int32 articleCount, System.Int32 expiryHours, System.Threading.CancellationTokenSource cancelToken, System.Boolean ignoreCache)
EDlib.GalNet    GalNetService.GetData (System.Int32 expiryHours, System.Threading.CancellationTokenSource cancelToken, System.Boolean ignoreCache)
EliteALD.ViewModels    NewsViewModel.GetGalNetNewsAsync (System.Threading.CancellationTokenSource cancelToken, System.Boolean ignoreCache)

To Reproduce

Steps to reproduce the behavior:

  1. Set calendar to Arabic, Saudi Arabia (ar_sa).
  2. Run app.
  3. Open GalNet.

Expected Behavior

GalNet parses & displays correctly.

Additional Context

Priorities, server status, BGS tick & CGs have no date issues but year is 42.

Arabic (ar_ar) & Arabic, United Arab Emirates (ar_ua) do not have these issues. Other Arabic calendars should be tested.

Firebase Screenshots

Linked To

51 Errors with non-Western calendars

63 Standings broken with some Arabic calendars

irongut/EliteALD Issue 304 GalNet & Standings broken with some Arabic calendars

irongut commented 3 years ago

Broken (12)

Arabic, Comoros (ar_KM) Arabic, World (ar_001) Arabic, Djibouti (ar_DJ) Arabic, Western Sahara (ar_EH) Arabic, Eritrea (ar_ER) Arabic, Mauritania Arabic, Palestine Arabic, Saudi Arabia (ar_SA) Arabic, Somalia Arabic, South Sudan Arabic, Sudan Arabic, Chad

Working (16)

Arabic (ar) Arabic, United Arab Emirates (ar_AE) Arabic, Bahrain (ar_BH) Arabic, Algeria (ar_DZ) Arabic, Egypt (ar_EG) Arabic, Iraq (ar_IQ) Arabic, Jordan (ar_JO) Arabic, Kuwait (ar_KW) Arabic, Lebanon (ar_LB) Arabic, Libya (ar_LY) Arabic, Morocco (ar_MA) Arabic, Oman Arabic, Qatar Arabic, Syria Arabic, Tunisia Arabic, Yemen

irongut commented 3 years ago

NewsArticleConverter.cs parses each article publish date & time on line 73. Passing a culture to the Convert.ToDateTime() call should fix the issue. Similar to recent fix for BGS Tick.

irongut commented 3 years ago

The Islamic Hijri calendar is the official calendar in countries around the Gulf, especially Saudi Arabia. Based on a lunar cycle and dates from the Prophet Muhammad's flight from Makkah to Madinah. The Islamic year (AH) averages 354 days and recedes by about 11 days a year against the Gregorian calendar.

Calendar Date
Hijri 08 / 09 / 1442
GREGORIAN 20 / 04 / 2021
irongut commented 3 years ago

An issue remains with the date displayed by the consuming app not appearing. image

The relevant Label controls are bound to NewsArticle.PublishDate which needs culture in a DateTime.ToString() call.