Overriding Dart's local time zone - dart

Dart's DateTime only supports UTC and "local" time. Is there a way to specify a local time zone when running tests, short of changing the time zone on the machine running the tests (or replacing DateTime with a time-zone-aware library)? See e.g. Java's user.timezone system property.

I think the clock package should be useful.
Run you test inside withClock()
test('clock', () {
withClock(Clock.fixed(DateTime.parse('2002-02-27T14:00:00-0500'), () {
// your test here
});
});

Related

Unison fails because it cannot set time stamp

Trying to sync from a mac to a linux machine, I get multiple failures with a message of the following type:
100% 00:00 ETAFailed [www/sandbox/my-vue-buefy-project/node_modules/spdy-transport/lib/spdy-transport/protocol/spdy]:
Failed to set modification time of file /users/guerrini/www/sandbox/my-vue-buefy-project/node_modules/spdy-transport/lib/spdy-transport/protocol/.unison.spdy.1db0b477154fc6ddf40346e8e27082da.unison.tmp/constants.js
to 1970-01-01 at 1:00:00 (0.000000):
the time was set to 2018-04-12 at 8:49:57 (1523515797.000000) instead`
It seems that it cannot set the modification time and that it uses the current time instead. But, unfortunately, after this the synchronisation of all the files with the above modification date fails.
Moreover, I have tried to set modification date to the given time by hand with "touch" and it works.

How to do time comparison between client's system time and date time from internet server (actual local time)

I am trying to validate the system time of client’s computer with the actual time (internet time). If for some reason the client’s time settings are not correct or the time and timezone don’t match the local time, I want to notify them to sync the time with their local time in order to use the application. If my question is not clear then this is something that I am trying to mimic, https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/Incorrect-System-time-warning-when-starting-an-Autodesk-360-application.html
How can I do this time comparison/validation in dart?
The main question is IMHO what accuracy you need.
You can just query a NTC and report if there is a discrepancy. If the server is synchronized with such a time server, there shouldn't be a problem.
You can also add an API to your server that returns the server time.
Then you read the time from the local system and from the server and check the difference
bool compareTime() {
var serverTime = await getTimeFromServer(); // not yet existing method to fetch the date and time from the server
var clientTime = new DateTime.now().toUtc();
var diff = serverTime.difference(clientTime).abs();
if(diff > const Duration(seconds: 5)) {
print('Time difference too big');
} else {
print('Time is fine');
}
}
Ensure that the time returned from the server is UTC as well, otherwise you're comparing apples with pears.
If you're running server-side, you can shell out to ntpdate -d pool.ntp.org and read the output, parsing the last line. If the time offset is small enough, you're good.
For browser apps, see the StackOverflow at Getting the current GMT world time for a few options.

Symfony Default timezone doesn't want to work if changed

At the moment i am trying to make a symfony app, but it gave me an error and couldn't start it's server when using the server:run command. It said that it couldn't run because of the timezone. If I change the timezone in the default php.ini file on a mac, it still gives me the error:
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezo
ne_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone
'UTC' for now, but please set date.timezone to select your timezone.
Can someone help me? I tried a lot, but can't figure this one out.
I want to change the timezone in the php.ini file that is being used by Symfony. But i don't know what i am doing wrong.
you can set it in your AppKernel (app folder):
class AppKernel extends Kernel
{
// the usuals.....
// Add this
public function __construct($environment, $debug) {
date_default_timezone_set('Europe/Warsaw');
parent::__construct($environment, $debug);
}
}

php 5.2.17 date('T') gives incorrect timezone. Server time+phpinfo time are correct

I am having a bit of a weird issue:
the date function gives timezone=MST
the date function from the centOS prompt gives me EST
the phpinfo() function returns America/New_York
As Plesk was showing America/New_York but centOS was not, Techsupport did something to the
/usr/share/zoneinfo/ files, because they said that somehow the New_York file was showing MST (Mountain Time).
After that operation, centOS time and phpinfo() display EST correctly but the date function still display MST.
Any ideas?
Did you tried date_default_timezone_set()?
Since PHP 5.1.0 (when the date/time functions were rewritten), every call to a date/time function will generate a E_NOTICE if the timezone isn't valid, and/or a E_WARNING message if using the system settings or the TZ environment variable.

Inno Setup: Specify Date in local format

My application uses Inno Setup to create some registry settings which are later read by an Excel addin. One of these settings is a date.
What I am looking for is a function (in Inno-Setup-friendly Pascal) that takes a date (formatted as a string) and outputs it using the local system date format on whatever computer it runs on. Something like
function GetLocalVersionOfShortDate(dateString : String): String;
begin
// take dateString and convert/display it as local date
end;
The output should be in short date format with the local date separator.
For example, I would pass "January 20, 1980" to this function and it would return "01/20/1980" (in America) and "20/01/1980" (in France).
Any thoughts on how to do that? I feel like it's something simple but I'm not familiar enough with Pascal to write the code myself.
Thank you!
There might be a way of doing this by calling into Windows libraries.
Check the section in the INNO help file called "Pascal Scripting: Using DLLs".
http://www.jrsoftware.org/ishelp/
ALTERNATIVE 1
You could do this by running an executable from either the Run section or via a function using the Exec method. If you are just writing registry settings then this should suffice. Then after the executable has run you could remove it by defining your own ssPostInstall method.

Resources