Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

[iOS] 接触日付が9時間ずれて表示される #64

Closed
b-wind opened this issue Mar 18, 2021 · 7 comments
Closed

[iOS] 接触日付が9時間ずれて表示される #64

b-wind opened this issue Mar 18, 2021 · 7 comments
Labels
invalid Issue の内容自体が正しくない、または適切でないと思われるもの

Comments

@b-wind
Copy link

b-wind commented Mar 18, 2021

不具合の内容 / Describe the bug

COCOA に置いて Xamarin.ExposureNotification は古いバージョンの物をリポジトリ内にコピーして利用しています。
このバージョンでは、ExposureInfo.Timestamp から取得出来る時刻データが、Android では UTC 、iOS では LocalTime であるというバグがあります。

COCOA としてはどちらもUTCとして扱っているようで、iOS 版を日本時間で利用していると日付表示時に9時間ずれて表示される事となります。

表示部分のコード。iOS 版では結果的に ToLocalTime() を二回通すため誤った日付が表示される。

var ens = new ExposureSummary();
ens.ExposureDate = en.Key.ToLocalTime().ToString("D", CultureInfo.CurrentCulture);
ens.ExposureCount = en.Count().ToString();
_exposures.Add(ens);

再現手順 / Steps to reproduce

  1. iOS / Android 環境を用意し、日本時間でCOCOAの利用を開始する
  2. 各端末で、15時〜24時の9時間の間に iOS / Android それぞれで接触がある状態にする
  3. 接触させた端末のうち、でAndroid 側で感染登録を行う
  4. 感染チェックのタスクが走った後、COCOAを起動し陽性者との接触を確認するボタンで遷移すると接触した日付の翌日が表示される。

上記の iOS , Android を逆にして実行すると接触した日付が表示される。

期待される挙動 / Expected behavior

Android と同様、接触した日付が表示される。

スクリーンショット / Screenshots

実機でのテストを行う環境が構築できないため、ありません。

動作環境 / Environments

  • デバイス:(実機でのテスト無し)
  • OS:(iOS)
  • バージョン:(all)

その他 / Additional context

解決策

  1. PR iOS の場合 ExposureInfo への保存がローカルタイム(ToLocaltime)となっている #1 を取り込む
  2. Xamarin.ExposureNotification を 0.13.0-preview 以降に更新する

Xamarin.ExposureNotification のオリジナルにおける修正と、PR #1@moonmile 氏による物で修正内容は同一です。

当方で再現環境が用意できないため、エミュレーター・実機による再現テストは行っていません。
念の為、現バージョン(1.2.2)での再現テストを推奨します。

This Issue was written with the help of @zipperpull .

@keiji keiji added bug バグ。本来あるべき動作をしていないもの waiting-for-confirmation 関係者に確認中のもの labels Mar 18, 2021
@keiji
Copy link
Collaborator

keiji commented Mar 19, 2021

接触時間が9時間早いものになる(日付が過去のものになる)と言う理解でいいですか?

そうだとするとこの現象で起こりうるユーザーの不利益は、

  • 濃厚接触の通知はされるものの、接触日付がずれて表示されることにより発症前2日の基準から外れて検査の必要なしと判断され、必要な医療措置を受けることが遅れる可能性がある

がありますね。

@tmurakami
Copy link

まず、Json.NET の DateTimeZoneHandling のデフォルトはRoundtripKind(Time zone information should be preserved when converting.)
https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonSerializerSettings_DateTimeZoneHandling.htm
https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_DateTimeZoneHandling.htm
https://www.newtonsoft.com/json/help/html/SerializeDateTimeZoneHandling.htm
とのことですので、iOS ではデシリアライズされた DateTime の Kind は Local になっているのではないかと思います。

そして、すでに Local な DateTime に対してToLocalTimeを実行しても変換はされないと明記されています。
https://docs.microsoft.com/ja-jp/dotnet/api/system.datetime.tolocaltime?view=net-5.0#--

ですので問題はないように思えます(確認はして欲しいです)が、修正はしておいたほうが良いとは思います。

個人的には、日時は UTC (か UNIX秒) で持って欲しいと思っています。

@b-wind
Copy link
Author

b-wind commented Mar 19, 2021

再現コードを書いてみたんですが、@tmurakami さんのご指摘の通り ToLocalTime を二重にかけても問題無い様に見えました。
先に確認しておくべきでしたすいません。

それとは別に、同じく DateTime なら UTC で持って欲しいのと、上流ですでに変更されている為 #1 は取り込んだ方が良いと考えます。

@ghost
Copy link

ghost commented Mar 19, 2021

私が確認せずに余計なこと言ったのですみませんでした

@keiji
Copy link
Collaborator

keiji commented Mar 19, 2021

余計なことではまったくないと思います。ユーザーが不利益を被る可能性が指摘されて、ひとまず直近で問題なさそうと言うことが明らかになるのは、とても有益なことです。

日付の持ち方を考えなければいけないのは本当にその通りですね。こちらについては念のためぼくの方で検証してからcloseする流れでいこうと思います。

他にもなにかおかしいと思うことがあれば遠慮なくIssueにしてください。

@keiji keiji added invalid Issue の内容自体が正しくない、または適切でないと思われるもの and removed bug バグ。本来あるべき動作をしていないもの waiting-for-confirmation 関係者に確認中のもの labels Mar 20, 2021
@keiji
Copy link
Collaborator

keiji commented Mar 20, 2021

検証した結果、ToLocalTime()を複数回実行しても日時はずれないことが確認されました。
本Issueをcloseします。

検証コードは次の通りです。

namespace XamarinExperiment.iOS
{
    // The UIApplicationDelegate for the application. This class is responsible for launching the 
    // User Interface of the application, as well as listening (and optionally responding) to 
    // application events from iOS.
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        //
        // This method is invoked when the application has loaded and is ready to run. In this 
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
#if ENABLE_TEST_CLOUD
            Xamarin.Calabash.Start();
#endif
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());

            var local1 = DateTime.Now.ToLocalTime();

            var data = new Data();
            data.Kind = local1.Kind.ToString();
            data.DateTime = local1;

            string json = JsonConvert.SerializeObject(data);
            System.Diagnostics.Debug.WriteLine(json);

            var data2 = JsonConvert.DeserializeObject<Data>(json);
            var local2 = data2.DateTime.ToLocalTime();

            System.Diagnostics.Debug.WriteLine($"Original {local1.Kind} {local1}");
            System.Diagnostics.Debug.WriteLine($"Deserialized {local2.Kind} {local2}");

            return base.FinishedLaunching(app, options);
        }
    }

    public class Data
    {
        public string Kind;
        public DateTime DateTime;

        public Data()
        {
        }
    }
}

実行結果は次の通りです。

{"Kind":"Local","DateTime":"2021-03-20T11:28:13.04539+09:00"}
Original Local 3/20/2021 11:28:13 AM
Deserialized Local 3/20/2021 11:28:13 AM

@keiji keiji closed this as completed Mar 20, 2021
@ghost
Copy link

ghost commented Mar 20, 2021

close いただいたのですが、#1 の取り扱いをどうするかの話だけ適宜対応お願いします
(PR のマージ or / and Xamarin.ExposureNotification の更新)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid Issue の内容自体が正しくない、または適切でないと思われるもの
Projects
None yet
Development

No branches or pull requests

3 participants