[Rd] creating POSIXct dates in C

From: Whit Armstrong <whit_at_twinfieldscapital.com>
Date: Sat 19 Feb 2005 - 07:09:48 EST

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 UTC. 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]]

R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Feb 19 07:32:49 2005

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:02:54 EST