This text is not a call to use javascript, vb (chur me), IIS, RSS, HTTP, TCP, IP and other non-Russian words, but describes a private solution to a particular problem.
It was possible recently to screw RSS for Yandex news to the site on ASP (vbscript). Everything, in general, was simple, but unexpectedly stumbled out of the blue - formatting the date. The date (pubDate) should be in the format of
RFC-2822 , and in the requirements of Yandex it is indicated that the time should not be UTC, but with the correct time zone corresponding to the placement of the resource. For example:
Fri, 25 Dec 2009 09:24:44 -0300 . A well-known thing, vbscript doesn’t really work with date itself: it knows one and a half of the bad format, and even those who want to use their localization by whim (I witnessed cases when I’m logged in to the console of the IIS + ASP + vbscript server, the locale of the logged-in user changed, changed date format and everything else, after which the application crashed with a crash). It was necessary to format the date without using the barsik's bearish services, and I went to Inet in reasoning to quickly dig up the appropriate code, and then go on to the meaningful work.
Right now!
As it sometimes (to be honest, quite often) happens, the code is found, but not the one. I formatted the date (the locale 1033 had to be nailed), but it turned out that the vbscript did not get the time zone of the host. Opanki. Well, not that absolutely nothing. Naryl on the Internet as much as 2 ways, one more beautiful than the other: the first through WMI, the second through an HTTP request to the local server. Perversion is natural. If you stop working, you are tormented to look for why it broke. And it will slow down like two floating anchors. In short, you can not do that, that's all.
In the end, there was a clever way (in fact, many people advise, for example, here:
http://ajaxandxml.blogspot.com/2006/02/computing-server-time-zone-difference.html ): an insert is added to the vbscript page on javascript, which is smarter than a leopard by an order of magnitude and somehow can work with dates. This resolved the issue with the time zone (time zone), but still there was no ready-made solution, I had to write a few lines. Then I dig a little more to work for non-integer time zones (they are said to be).
It turned out this:
')
<%@ LANGUAGE="VBSCRIPT" %> <SCRIPT Language="JavaScript" Runat="Server"> function zeroPad(num, width) { num = num.toString(); while (num.length < width) { num = "0" + num; } return num; } function fmtRssDate(dUTC){ var offset = -((new Date()).getTimezoneOffset()); var offsetH = Math.floor(Math.abs(offset) / 60); var offsetM = Math.abs(offset) - offsetH * 60; var sOffset = ((offset >= 0) ? "+" : "-") + zeroPad(offsetH, 2) + zeroPad(offsetM, 2); var localTime = new Date(dUTC - offset * 60000); var sLocalTimeWithOffset = localTime.toUTCString(); sLocalTimeWithOffset = sLocalTimeWithOffset.substring(0, sLocalTimeWithOffset.indexOf("UTC")); sLocalTimeWithOffset += sOffset; return sLocalTimeWithOffset; } </SCRIPT> <%=fmtRssDate(now())%>
Everything.