MonoTouch DateTime.ToLocalTime does not update when time zone is changed - ios

When I change the time zone on my computer (when testing on the simulator) or on the phone (when testing directly on the phone), DateTime.ToLocalTime() does not return updated results.
I register and successfully receive notification events for UIApplication.Notifications.ObserveSignificantTimeChange. In it I call TimeZoneInfo.ClearCachedData() which allows me to detect the time zone has in fact changed but this has no effect on ToLocalTime(). The DateTime I am converting is definitely of kind Utc (tried DateTime.UtcNow for example).
I tried calling CultureInfo.CurrentCulture.ClearCachedData() as suggested in this question: SetTimeZoneInformation does not update DateTime.Now for another .NET Application. That only causes the application to crash when the CurrentCulture is nulled.
Digging a bit deeper into the implementation of ToLocalTime(), it seems to use the object TimeZone.CurrentTimeZone. This object is reset only when the difference between DateTime.GetNow() and TimeZone.timezone_check. I suspect that TimeZone.timezone_check is not getting updated when TimeZoneInfo.ClearCachedData() is called.
Is there any way I can force ToLocalTime() to take into consideration the time zone change?

You can use DateTimeOffset for this. See also this question.
Edit - What I have working is this:
var dateTimeUtc = new System.DateTime(2013, 2, 4, 21, 30, 0,
System.DateTimeKind.Utc);
var dateTimeOffsetLocal = new System.DateTimeOffset(dateTimeUtc.ToLocalTime());
var formattedLocalTime = string.Format("{0:HH:mm}", dateTimeOffsetLocal);
On my phone my formattedLocalTime changes whenever I change my TimeZone on it, without clearing any cache. I do have to reload the view, but no other tricks.
To display/verify the local TimeZone I use:
var localTimeZone = System.TimeZoneInfo.Local.StandardName;
I hope this somehow points you in the right direction. I don't have any better than this "works on my machine(s)"-anwer.

Related

SIM800L Date and Time is not working. How to convert from int to string?

I am currently working on a device and it sends data to Firebase. Unfortunately, I am unable to send the correct time and date.
CONVERT TIME INT TO STRING
I tried setting the time but it ignores the changes.
AT+CLTS=1 should enable network time sync.
AT+CLTS? will check if it is set.
AT&W should save the setting in permanent memory.
AT+CCLK? should display the correct time in the end.
SET TIME AND NETWORK TIME NOT WORKING
The AT&W command most likely does not save gsm network settings .
String arguments to at commands must be enclosed with double quotes, e.g. AT+CCLK="...".

How to fix: bug starting 8/20/2019: UsedRange returns null Values

Starting around 1AM PST on 8/20/2019, the UsedRange.Values property has started returning null.
Not on all Excel spreadsheets but on some, and we can't yet determine what factors cause it. Seems like a bug in the graph APIs, as this was working seamlessly for more than a year.
var getUsedRangeRequest = _sheetRequestBuilder.UsedRange().Request();
usedRange = getUsedRangeRequest.GetAsync().Result;
I expect usedRange.Values to be a non-null JToken and so we can access usedRange.Values.Children().ToList() .... etc.
Thanks for reporting this issue. This is recovered now. Could you please try again?

How to save information ( Swift application )

I am developing an iOS application which generate random inspirational quote every day. At the moment when I close the app, open it again and click on the button which generates the daily quote, it shows me a new one.
Can you help me, how can I save the same quote all over the day and when the day is over generate a new quote. I mean at 00:00 o'clock in the morning.
I want to keep 1 quote per day, not 1 quote for every time I open the app.
Okay, I have some time on my hands and I can provide you a small tutorial on how to save data to the user defaults.
You will want to save the date on which you create a quote right after you created it and then each time your app goes to foreground check against that. Obviously you want to only remember the day, not the hours, minutes and seconds. Here's a small function for that:
func makeCleanToday() -> NSDate {
let today = NSDate()
let comps = NSCalendar.currentCalendar().components([.Day, .Month, .Year], fromDate: today)
return NSCalendar.currentCalendar().dateFromComponents(comps)!
}
Note that this forcibly unwraps the date on the last line, but this is fine here, since I do nothing that could lead to dateFromComponents returning nil.
The next two lines you will always call right after you created your quote:
let cleanToday = makeCleanToday()
NSUserDefaults.standardUserDefaults().setObject(cleanToday, forKey: "MyAppDateKey")
Obviously you should use a better key to identify this (I suggest defining a constant somewhere for this). This saves your date (only day, month and year) in the app's user defaults.
Next time your app goes into the foreground (use the app delegate for this), then do this here:
if let savedDate:NSDate = NSUserDefaults.standardUserDefaults().objectForKey("MyAppDateKey") as? NSDate {
let cleanToday = makeCleanToday()
if savedDate.earlierDate(cleanToday) == savedDate {
// create new sentence
NSUserDefaults.standardUserDefaults().setObject(cleanToday, forKey: "MyAppDateKey")
}
} else {
// create new sentence
NSUserDefaults.standardUserDefaults().setObject(makeCleanToday(), forKey: "MyAppDateKey")
}
Please note that I added the two NSUserDefaults.standardUserDefaults().setObject.... lines here just to illustrate what happens. You will probably have that code already in your quote creation method, like I told you above to do. Also, the else part of this is for when you run the app the first time. Then you don't have anything saved in the user defaults, so savedDateis nil and you have to create your quote as normal.
Lastly a general remark: Using NSCalendar is relatively expensive (though it is designed for this scenario), so you shouldn't use it, for example, when filling cells in a table or something (because that might negatively affect frame rate during scrolling). In this case it's perfectly fine (relatively being the keyword here), I just wanna let you know before you eventually advance with your coding to a point where you run into this. :) Same is true for date formatters.
Oh, and regarding the comment: No need to say sorry, I just wanted to let you know how things here on SO are and cushion the fall a bit when you see your question getting downvoted. I hope this could help you.

Sencha iOS picker bug

My app is nearly completed, but there's one bug which I have to get sorted before release. The app uses Cordova 3.4 and Sencha to build a "native" app for iOS and Android (the bug only relates to iOS)
Basically, when the picker value is changed, unless the user is quick enough in how they click Done, it reverts to the previous value - hard to explain! Here is a video showing the bug in action.
As mentioned before, this is only a problem on iOS (Android is fine). It is also worth noting that when there are two value options in other pickers in the app this bug does not exist. For example, the picker for time (hours & minutes) and date (day & month) do not have this bug - only single value pickers have the issue.
Any ideas?
I have just had to fix this issue within our product, and boy debugging on the iPhone is a right pain when you only have a Windows desktop!
Essentially what seemed to be happening was that when a slot's selection changed, the internal selectedIndex property was being updated, however the _value was not - and it seems that it's the _value that is being consulted.
I created a new slot class as follows, that overrides doItemTap to ensure that value is set appropriately (me._value = me.getValue(true);):
Ext.define('Ext.ux.FixedSlot', {
extend: 'Ext.picker.Slot',
xtype : 'fixedslot',
doItemTap: function(list, index, item, e, event) {
var me = this;
me.selectedIndex = index;
me.selectedNode = item;
me._value = me.getValue(true);
me.scrollToItem(item, true);
}
});
Then in my picker definition config (we have a class defined as a subclass of field.Select), I instructed it to use my new slot type (defaultType: 'fixedslot'):
Ext.define('Ext.ux.MyFixedPicker', {
extend: 'Ext.field.Select',
config : {
defaultPhonePickerConfig : { defaultType: 'fixedslot' }
}
});
I'm hoping that helps you avoid some of the pain of my last six hours! I still can't explain exactly why/where in the Sencha Touch source that's important, but for right now it appears to fix the problem and meet our packaging deadline!

WinRT Geolocator always return the same position

We have a strange behavior with the WinRT Geolocator in one of our app. The user clicks on a button in the app to get the current position. Works fine the first time but all subsequent click on the button returns the same coordinates even tough we move for more than one kilometer.
The application runs on a ThinkPad and we've installed an application called "GPS Satellite" and if we switch to this application, get a coordinates, and return to our app then the Geolocator returns the correct coordinates. So we know the GPS is working fine, but seems like the coordinates are kept in cache even tough we've set a expiration of a few millisecond.
private async void ExecuteObtenirCoordGPSCommand()
{
try
{
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracy = PositionAccuracy.High;
// Make the request for the current position
Geoposition pos = await geolocator.GetGeopositionAsync(new TimeSpan(0,0,0,0,200), new TimeSpan(0,0,5));
Place.Latitude = pos.Coordinate.Latitude;
Place.Longitude = pos.Coordinate.Longitude;
}
catch
{
GPSMsgErreur = "The GPS is unavailable";
}
}
We've tried to put a expiration on the method GetGeopositionAsync but it didn't solved the problem.
We've tried to put the Geolocator var at the class level with the same result.
Any ideas?
Not sure if this is your issue but the API you are using is tagged has obsolete in this post:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geocoordinate
Try using:
Place.Latitude = pos.Coordinate.Point.Position.Latitude;
Place.Longitude = pos.Coordinate.Point.Position.Longitude;
You may also use:
double someVar = pos.Coordinate.Accuracy
to figure out what is the margin of error on the device. May be you where not far enough from your first location and your second location was within the margin of error...
I can also tell you that I have a software built with Visual Studio 2013 Windows (WinRT) that runs on a ThinkPad using the same objects you are using and it works fine.
The main difference between mine and yours is that I am using the API showed above and that I did not use the following statement:
geolocator.DesiredAccuracy = PositionAccuracy.High;
And that I did not pass any parameters to the GetGeopositionAsync method.
I hope this helps.
Cheers, Hans.

Resources