Question
· Apr 3, 2017

How to convert date into string regardless of locale

I need to convert timestamp into HTTP-date as defined in section 3.3.1 of [RFC2068] HTTP-Date can have several representations, but preferable view is defined by RFC 822, updated by RFC 1123 and looks like this:

wkday "," SP date1 SP time SP "GMT"

Here's an example of HTTP-date value:

Sun, 06 Nov 1994 08:49:37 GMT

The problem I encountered, is that if server locale is not English, then $zd, $zdt and TO_CHAR return localized names of weekday and month (i.e: Вос). Is there a way to get English names of weekday and month regardless of server locale?

 

Just checked TO_CHAR and it also calls $zd.

Discussion (3)1
Log in or sign up to continue

localeopt parameter solved the problem. This Boolean parameter specifies either the user’s current locale definition or the ODBC locale definition as the source for defaults for the locale-specified parameters dformat, monthlist, yearopt, mindate and maxdate:

  • If localeopt=0, all of these parameters take the current locale definition defaults.
  • If localeopt=1, all of these parameters take the ODBC defaults.

For example:

write $zd($h,11,,,,,,,,1)
>Mon

Hi Eduard,

I came across this post from 2 years ago when trying to work out the simplest way to get current RFC 822/1123 HTTP-Date values from current timestamps for a request header value (eg the %Net.HttpRequest 'Date' property) in something I'm working on.

At the risk of telling you something you've found out elsewhere since then, it turns out there's already a classmethod that will output this (in GMT) from $horolog (or any $horolog-style ddddd,sssss value, with the assumption it's in local time/date):

write ##class(%CSP.StreamServer).ToHTTPDate($horolog)
>Fri, 18 Jan 2019 04:09:44 GMT

write $zdatetime($horolog,2)
>18 Jan 2019 15:09:44  //AEST timestamp

The Documatic details are here.

Cheers

Joe