Skip to main content

Azure App Service: Offline Sync – Do not use CreatedAt for Display

In the Azure App Service Mobile Client Offline Sync:

With offline sync, the CreatedAt field for a new record that has not been synced is null. If you set CreatedAt to DateTime.Now or another value, on sync, CreatedAt will be replaced with the DateTime of when the sync occurred (used for incremental syncs among other things). If you need to have a created time that corresponds to the actual time the user created the record, created your own property, say DateUTC, and set it yourself to DateUTC.Now;. This value will not change. The only concern with doing this is if the user somehow has the date wrong on their device, the DateUTC will be wrong as well. Hopefully everyone has figured out that having their device date/time set automatically is a good thing.

//setting the object
        var customObject = new CustomObject
        {
            DateUTC = DateTime.UtcNow,
        };

//to display it in the local time
        [JsonIgnore]
        public string DateDisplay { get { return DateUTC.ToLocalTime().ToString("d"); } }

        [JsonIgnore]
        public string TimeDisplay { get { return DateUTC.ToLocalTime().ToString("t"); } }

John

John Rennemeyer is a software engineer that started his own development company MuvEnum, LLC in 2005. Born in Utah, he is a father of six, husband of one, and grandparent of none. His current programming passions include Xamarin, WPF, SharePoint, and their supporting technologies. His current non-programming passions include spending time with his family and hanging out with friends while enjoying food and fun. How's that for specific?