[Rd] creating POSIXct dates in C

Whit Armstrong whit at twinfieldscapital.com
Fri Feb 18 21:09:48 CET 2005

I'm trying to generate POSIXct times in a call to a C function.
However, I'm having trouble generating times with the proper offset from

Can anyone offer any help with this issue?

I've looked at R-2.0.1/src/main/datetime.c, but I was not able to find
an example that I could easily pull from that file.

Thanks in advance,

Here is my example in C:

#include <stdio.h>
#include <time.h>

int main() {
  struct tm localtime_tm;
  struct tm utc_tm;

  time_t localtime_posix;
  time_t utc_posix;

  char buf[255];

  strptime("1970-01-01", &localtime_tm);
  localtime_posix = mktime(&localtime_tm);

  // this prints 0
  // which is what the time would be if we were in GMT
  // how do we convert this time to our timezone
  // taking into account that the offset is not
  // constant, since daylight savings time
  // will shift the offset by an hour
  // for certain times

  // now convert it to gmtime
  gmtime_r(&localtime_posix, &utc_tm);
  utc_posix = mktime(&utc_tm);

  // this still prints 0
  // how do I convert it to a utc time
  // representing 1970-01-01 in EST ??


> R.Version()
[1] "i686-pc-linux-gnu"

[1] "i686"

[1] "linux-gnu"

[1] "i686, linux-gnu"

[1] ""

[1] "2"

[1] "0.1"

[1] "2004"

[1] "11"

[1] "15"

[1] "R"

RHEL 3.0

	[[alternative HTML version deleted]]

More information about the R-devel mailing list