mIRC Homepage
Posted By: Thels $utc - 13/07/15 09:10 AM
The $gmt value seems a bit flaky. I assumed it displayed the number of seconds that have passed since January 1 1970 01:00:00, but it seems I was wrong.

I live in GMT+1. Daylight saving time is currently in effect, which adds another hour, so I'm 2 hours ahead of Coordinated Universal Time.

I wrote an alias to echo the following variables at the exact same time:
$fulldate: Mon Jul 13 11:00:17 2015
$ctime: 1436778017
$calc(($ctime % 86400) / 3600): 9.004722
$gmt: 1436770817
$calc(($gmt % 86400) / 3600): 7.004722
$daylight: 3600
$timezone: -7200

86400 is 60 * 60 * 24, thus, the number of seconds in a day. The number of seconds should have been from Januari 1 1970 at 01:00:00, so considering it's 11 o'clock local time, it should've been 10 o'clock without daylight saving time, or 9 o'clock universal time, which is 8 hours after that 1 o'clock. However, $gmt is only 7 hours past a full number of days, so it accounts for daylight saving time somewhere. Still, $ctime is still 2 hours ahead of $gmt.

This is all really flaky to work with. Sure, $asctime will give me the correct date and time, but with timers and stuff, it's a lot easier to work with the original numbers, than convert them to time, and decypher the values from there.

Could you add a function such as $utc that returns the exact number of seconds that have passed since a certain moment in the past, without correcting itself to Daylight Saving Time in any way? Preferably, this would start counting from midnight GMT (such as Jan 01 1970 00:00:00), so it's easy to calculate the exact number of days that have passed since then.

Kind regards,
Posted By: Khaled Re: $utc - 13/07/15 04:41 PM
Thanks for your post. Unfortunately I have not been able to reproduce an issue with the $gmt identifier so far. I have tested it under different versions of Windows, using different timezones, both with and without daylight savings enabled, and it always matches the GMT time value. Can you provide a little more information, such as which version of Windows you are using and which timezone you have set in the Windows date/time dialog?
Posted By: Thels Re: $utc - 15/07/15 08:56 AM
Windows 7 Ultimate 64bit NL, Service Pack 1.

(UTC+01:00) Amsterdam, Berlijn, Bern, Rome, Stockholm, Wenen

When I do $asctime($gmt), I do get the correct current universal time. But if I try to work with the number of seconds itself, for example, to see how much time has passed or to set up timers, I'm a little confused. I thought $ctime and $gmt were meant to count back to January 1 1970 00:00:00, but if I try this at 10:36 am local time:

//echo GMT: $calc(($gmt % 86400) / 3600) CTIME: $calc(($ctime % 86400) / 3600)

GMT: 6.601111 CTIME: 8.601111

So CTIME doesn't count back to midnight, but to 2 am (which would be Midnight in universal time), whereas GMT counts back to 4 am (2am universal time).

EDIT: I've been messing some more, and it seems I've simply been misunderstanding how these values work.

$ctime actually provides the number of seconds that have passed since 1-1-1970 00:00:00 GMT, regardless of what timezone you're in, or if daylight savings is active.

$asctime takes a timevalue, and returns a readable format that is adjusted to the current timezone.

$gmt provides a certain timevalue that opposes the current timezone, so that $asctime would come up with the readable format for GMT.

I had assumed that $ctime would be adjusted to your local timezone, and $gmt would be universal, but it's actually opposite. It's a bit confusing at first.

So yeah, apologies for my initial request.

I still have a request, though. It would be nice if there was an alternative for $asctime that would display the GMT/UTC time (without DST) for a certain $ctime value, without having to set my computer's timezone to GMT/UTC.

For example, if I stored $ctime values of events in the past, I want to know the actual GMT/UTC times of those moments. I can't subtract my current timezone, because I don't know if my current timezone was the same back then, due to DST. Something like an $ascgmt would be nice for that.
© mIRC Discussion Forums