I think finding out if this enabled will not be possible (I’m not sure, maybe there is some compiled plugin that solves, so far I found nothing), but can try to compare the value of "API Date
javascript native:
And create a page with HTTP response in any format, for example JSON, that returns the time of your server, being this page configured with the desired Timezone.
For example to get the Timezone of the mobile would be this:
let tz = new Date().getTimezoneOffset();
console.log(tz);
Or take the current time and compare with some API service (own or third party):
console.log(new Date().toString());
And with an HTTP request using $http
could get the data from the server and compare them, which will require some development in the back end, however as an alternative there are third party services that return this type of data, as the own of google maps: https://developers.google.com/maps/documentation/timezone/intro
Then you could send the requisition to $http
for:
https://maps.googleapis.com/maps/api/timezone/json?location=<LATITUDE>,<LONGITUDE>×tamp=<TEMPO ATUAL EM SEGUNDOS>&key=<SUA CHAVE DA CONTA DE DESENVOLVEDOR GOOGLE>
You’ll have to use something to pick up the user’s current location, so change:
<LATITUDE>
by the caught longitude
<LONGITUDE>
by the caught longitude
<TEMPO ATUAL EM SEGUNDOS>
for Date.now()
<SUA CHAVE DA CONTA DE DESENVOLVEDOR GOOGLE>
your developer key, you must have developer account to use Google Maps services.
Another possible solution would be to use the service https://timezonedb.com/api (there are others of the same type), in the case Would use this function: https://timezonedb.com/references/get-time-zone
For some actions in the app, I need to ensure that the user is with Automatic Time Zone enabled, so that they do not send data with false date/ time, if they are not able to proceed.
In this case simply send the request time next to the payload, something like:
$http({
url: 'http://foo.bar/api/foo/bar',
method: 'POST',
data: {
'foo': $scope.foo,
'bar': $scope.bar,
'time': new Date().toUTCString()
}
}).then(function (response) {
console.log("sucesso", response);
}, function (response) {
console.log("falhou", response);
});
Of course take into account that Brazil has different time zones, so it would be interesting to send in UTC to do from this the back-end check, so in your HTTP server, where will communicate with your service, check the parameter time
payload, in your case I think it is PHP, so I would do this:
strtotime($_POST['time']);
Then you will have the value in seconds, which can use the gmdate
(I think it would be this, I haven’t tested it yet) and compare it to the server values, only for the year, month and time. Minutes may be irrelevant and may not be very precise.
I didn’t create anything, but it’s just the idea for you to implement it yourself.
After your edition I understood more your need, so I added a few more things in the answer, with a "theoretical" example, just to understand the idea.
– Guilherme Nascimento