mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2017
Posts: 9
M
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Jun 2017
Posts: 9
Hey Guys,

Is there a way to convert a zulu timestamp (from a variable) to GMT+1?

Current format: 2013-01-10T13:13:13Z (yyyy-mm-dd HH:mm:ss)
Would like to convert to dd.mm.yyyy HH:mm:ss without the "T" and the "Z"

Thanks in advance.

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
This seems to work. The +1 is for the GMT+1, not because of $daylight setting.

Code:
//echo -a $gmt( $calc($ctime($replace(2013-01-10T13:13:13Z,t,$chr(32),z,$chr(32))) - $timezone +1*3600),dd.mm.yyyy HH:nn:ss) 



Since your example used an old date, beware that certain date ranges may be off prior to 2006 due to assuming the current rules were in effect then.

https://forums.mirc.com/ubbthreads.php/topics/264232/$asctime_daylight_rules#Post264232

Joined: Jun 2017
Posts: 9
M
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Jun 2017
Posts: 9
Originally Posted By: maroon
This seems to work. The +1 is for the GMT+1, not because of $daylight setting.

Code:
//echo -a $gmt( $calc($ctime($replace(2013-01-10T13:13:13Z,t,$chr(32),z,$chr(32))) - $timezone +1*3600),dd.mm.yyyy HH:nn:ss) 



Since your example used an old date, beware that certain date ranges may be off prior to 2006 due to assuming the current rules were in effect then.

https://forums.mirc.com/ubbthreads.php/topics/264232/$asctime_daylight_rules#Post264232



Thanks a lot this is working. And thanks for the information regarding the old date smile - i not have any timestamp prior 2010 smile

Joined: Jun 2017
Posts: 9
M
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Jun 2017
Posts: 9
Hey maroon,

one problem come to my attention:
the timestamp will not be converted to normal time (+1) and summertime (daylight saving time / +2) is there any way for this?

e.g. output:
2013-03-10T13:13:13Z => normal time with GMT+1 => (10.03.2013 13:13:13 +0100)
2015-05-28T23:14:41Z => summertime GMT+2 => (28.05.2015 23:14:41 +0200)

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
Right, I noticed this after I posted, and hoped I'd have time to test further before you noticed too. $gmt is behaving like it's just another timezone N hours away from the script, which goes on/off daylight time the same calendar time as you do.

A work-around would be calculating the difference between if hours:minutes on the target day compared to that same hours:minutes for today. If that's a multiple of 86400, then both days are either both inside or both outside summertime, and no adjustment is needed. Depending on whether you're peeking into or out of summertime, you might need to adjust +1 or - 1 hours. There might need further calculation to get the right answer for a short period on the day when the clock gets changed by 1 hour, but I'd need to test to confirm.

https://forums.mirc.com/ubbthreads.php/topics/265145/$gmt(number)

Joined: Jun 2017
Posts: 9
M
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Jun 2017
Posts: 9
Originally Posted By: maroon
Right, I noticed this after I posted, and hoped I'd have time to test further before you noticed too. $gmt is behaving like it's just another timezone N hours away from the script, which goes on/off daylight time the same calendar time as you do.

A work-around would be calculating the difference between if hours:minutes on the target day compared to that same hours:minutes for today. If that's a multiple of 86400, then both days are either both inside or both outside summertime, and no adjustment is needed. Depending on whether you're peeking into or out of summertime, you might need to adjust +1 or - 1 hours. There might need further calculation to get the right answer for a short period on the day when the clock gets changed by 1 hour, but I'd need to test to confirm.

https://forums.mirc.com/ubbthreads.php/topics/265145/$gmt(number)


Okay, after hours of testing, i did not find any working solution to determine if the target (timestamp as above) time is in daylight period or not... did you find any further?

Thank for your help so far.

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
The issue is not whether the target date is inside/outside summertime, but whether it's in the opposite condition as the current time.

Code:
alias datefix {
  var -s %a $replace(2013-01-10T13:13:13Z,t,$chr(32),z,$chr(32))
  var -s %b $date $gettok(%a,2,32)
  var -s %a2 $ctime(%a) , %b2 $ctime(%b)
  var -s %fix $calc( (%b2 - %a2) % 86400)
  return %fix
}


This will return
82800 = today is during summertime, target day is not
0 = today and target day are either both inside or both outside summertime
3600 = target day is within summertime, today is not

And as I mentioned in my post, if either today or the target day, or both, is one of the twice per year day of transition between on/off summertime, it might need further adjustments to the formula.


Link Copied to Clipboard