2016-10-06 4 views
0

Xamarin FormsアプリケーションのAzureMobileServicesClient SQLiteデータベースにIDとDateTimeOffsetを持つエンティティを保存しようとしています。Azure Mobile AppsがSqliteデータベースに間違った日時を保存する

タイムスタンプが曖昧でない限り、この作業は問題ありません。夏時間から標準時間に移行すると、タイムゾーンによってタイムスタンプがあいまいになることがあります。デンマークの2016年10月30日午前2時00分〜3時です。

エンティティDateTimeOffsetをUTCとして保存しますが、ローカルタイムスタンプとして保存します。

曖昧なタイムスタンプを2016-10-30 12:30 AM + 0:00と保存すると、2016-10-30 11:30 AM +0:00に戻ります。 私はこれを他のタイムゾーンでテストしましたが、夏時間からその特定のタイムゾーンの標準時間への移行中にあいまいな時間が発生するだけです。 http://www.thomaslevesque.com/2015/06/28/how-to-retrieve-dates-as-utc-in-sqlite/
をしかし、私はAzureMobileSerivesを使用していますので、解決策は、この場合には動作しません:

私はここで、通常のSQLiteのデータベースのための固定の問題を見てきました。

私はAzureMobileServiceを初期化するこのコードで

、これはXamarinアプリケーションですBecuase

public static class SaveTimeStamp 
{ 
    public static async Task Save() 
    { 
     //Init mobile service Client 
     var mobileService = new MobileServiceClient(Configuration.MobileAppsUrl); 

     //init MobileService Database 
     var dataStore = DependencyService.Get<IDataStore>(); 
     var path = dataStore.GetPath("store.db"); 
     dataStore.CreateFile(path); 
     var store = new MobileServiceSQLiteStore(path); 

     store.DefineTable<Entity>(); 
     await mobileService.SyncContext.InitializeAsync(store, StoreTrackingOptions.NotifyLocalAndServerOperations).ConfigureAwait(false); 
     var entityTable = mobileService.GetSyncTable<Entity>(); 

     //Save entity with ambiguous timestamp 
     var ambiguousTimestamp = new DateTimeOffset(2016, 10, 30, 0, 30, 0, TimeSpan.Zero); //UTC: 30th of October 12:30 AM + 0:00 => DK time:30th of october 2:30 AM + 2:00 

     var entity = new Entity 
     { 
      Id = Guid.NewGuid().ToString(), 
      Timestamp = ambiguousTimestamp 
     }; 

     Debug.WriteLine("Saving datetime UTC: " + entity.Timestamp.UtcDateTime); 

     await entityTable.InsertAsync(entity).ConfigureAwait(false); 

     //Fetch saved entity 
     var refecthedEntities = await entityTable.Where(e => e.Id == entity.Id).ToListAsync(); 
     var refecthedEntity = refecthedEntities.FirstOrDefault(); 

     if (refecthedEntity.Timestamp != ambiguousTimestamp) 
     { 
      Debug.WriteLine("Refecthed datetime UTC do not match: " + refecthedEntity.Timestamp.UtcDateTime); 
     } 
     else 
     { 
      Debug.WriteLine("Refecthed datetime UTC: " + refecthedEntity.Timestamp.UtcDateTime); 
     } 

     //output 
     //[0:]Saving datetime UTC: 10/30/2016 12:30:00 AM 
     //[0:]Refecthed datetime UTC do not match: 10/29/2016 11:30:00 PM 
    } 
} 

class Entity 
{ 
    public string Id { get; set; } 
    public DateTimeOffset Timestamp { get; set; } 
} 

に異なる出力を見るためにあいまいなタイムスタンプを保存し、再びそれを盗んし、画面に2回を書き出します私はまた、データベースを初期化するためのxamarin.ios proejctにいくつかのコードを持っています。

//IN Xamarin.IOS 
[Register("AppDelegate")] 
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate 
{ 

    public override bool FinishedLaunching(UIApplication app, NSDictionary options) 
    { 

     global::Xamarin.Forms.Forms.Init(); 
     Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init(); //Init Azure mobileservies on IOS Current IOS 9.3 
     SQLitePCL.CurrentPlatform.Init(); 

     LoadApplication(new App()); 

     App.ScreenWidth = (int)UIScreen.MainScreen.Bounds.Width; 
     App.ScreenHeight = (int)UIScreen.MainScreen.Bounds.Height; 

     return base.FinishedLaunching(app, options); 
    } 

    public override void WillEnterForeground(UIApplication uiApplication) 
    { 
     base.WillEnterForeground(uiApplication); 
     uiApplication.IdleTimerDisabled = true; 
    } 

    public override void DidEnterBackground(UIApplication uiApplication) 
    { 
     base.DidEnterBackground(uiApplication); 
     uiApplication.IdleTimerDisabled = false; 
    } 
} 

私は、エンティティに代わりのDateTimeOffsetの日時を使用してのみDateTimeKind = UTCを使用しようとしましたが、私は同じ結果を得ました。

+0

どのようにDateTimeを保存しますか?ティックとして? –

+0

これはフレームワークによって決まります。エンティティクラスにDateTimeOffset型のDateプロパティがあります。 Sqliteデータベースを調べると、あるオフセットから秒数として保存されます。 – LJA

+0

本当に、AsTicksは確かにデフォルト設定です。ただそれを確認したかったのです。 SqLiteはこれに問題はないので、確かにAzureサービスの問題です。 –

答えて

0

これは既に報告バグのようになります。https://github.com/Azure/azure-mobile-apps-net-client/issues/131

は、バグを追跡すること自由に感じなさい。

+0

はい、Sqliteクライアントデータベースには、DateTimeがUTCではなくLocalとして格納されています。このバグが解決されているのか、修正が必要なのか分かりますか? – LJA

+0

現在リリース予定はありません。私は今週末にそれを見て、何が関係しているのか見てみましょう。フロントエンドとバックエンドでGitHubリポジトリを最小限のreproで使用すると便利です。 (そうでなければ、私は時間をかけて1つを作り出す必要があります)。そうした場合は、問題に追加してください。 –

+0

申し訳ありませんが、私は顧客のアプリケーション用にモバイルアプリを使用しており、アプリケーション全体をGitHubに入れることはできません。 – LJA

関連する問題