Thread overview | |||||
---|---|---|---|---|---|
|
August 12, 2018 SysTime comparesin - dropMiliseconds | ||||
---|---|---|---|---|
| ||||
I have to synchronize a directory. If remote file is newer I copy to local. If local file is newer I copy it to remote server. For some reason remote timestamp does not contain milliseconds, so comparison (localFileTime < remoteFileTime, etc) fails. I need help to drop milliseconds from local file timestamp. |
August 12, 2018 Re: SysTime comparesin - dropMiliseconds | ||||
---|---|---|---|---|
| ||||
Posted in reply to User | On Sunday, 12 August 2018 at 19:50:44 UTC, User wrote:
> I have to synchronize a directory. If remote file is newer I copy to local. If local file is newer I copy it to remote server. For some reason remote timestamp does not contain milliseconds, so comparison (localFileTime < remoteFileTime, etc) fails. I need help to drop milliseconds from local file timestamp.
auto m = dur!("seconds")(1);
if ((remote - local) > m)
|
August 12, 2018 Re: SysTime comparesin - dropMiliseconds | ||||
---|---|---|---|---|
| ||||
Posted in reply to User | On Sunday, August 12, 2018 1:50:44 PM MDT User via Digitalmars-d-learn wrote:
> I have to synchronize a directory. If remote file is newer I copy to local. If local file is newer I copy it to remote server. For some reason remote timestamp does not contain milliseconds, so comparison (localFileTime < remoteFileTime, etc) fails. I need help to drop milliseconds from local file timestamp.
If you want to drop the milliseconds from a SysTime, you can always set its fracSecs to Duration.zero. e.g.
st1.fracSecs = Duration.zero;
if(st1 < st2)
{
...
}
You could also cast the two SysTimes to DateTime and compare the result (since DateTime doesn't have fractional seconds), but you'd probably want to use toUTC() to ensure that the SysTimes had the same time zone when converting, or you'd risk subtle bugs. e.g. something like
if(cast(DateTime)st1.toUTC() < cast(DatetTime)st2.toUTC())
{
...
}
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation