#line 1240 "/home/travis/build/felix-lang/felix/src/packages/web.fdoc"
  class LowResTime
  {
    open C_hack;
  
    requires C89_headers::time_h;
  
    type time_t = "time_t";
    fun +: time_t*time_t -> time_t = "$1+$2";
    fun +: time_t*int -> time_t = "$1+(time_t)$2";
  
    Current time
    proc time: &time_t = "time($1);";
  
    Current time
    ctor time_t () = {
      var time_v:time_t;
      time(&time_v);
      return time_v;
    }
  
  
    // cast integer (in second since epoch) to time
    ctor time_t: !ints = "(time_t)$1:cast" is cast;
  
    cstruct tm {
      tm_sec:int;         /* seconds */
      tm_min:int;         /* minutes */
      tm_hour:int;        /* hours */
      tm_mday:int;        /* day of the month */
      tm_mon:int;         /* month */
      tm_year:int;        /* year */
      tm_wday:int;        /* day of the week */
      tm_yday:int;        /* day in the year */
      tm_isdst:int;       /* daylight saving time */
    };
  
  
  if PLAT_WIN32 do
    private proc gmtime:&time_t * &tm = "gmtime_s($2,$1);";
  else
    private proc gmtime:&time_t * &tm = "gmtime_r($1,$2);";
  done
  
    fun gmtime (var t:time_t) :tm =
    {
      var atm : tm; gmtime (&t, &atm);
      return atm;
    }
  
  if PLAT_WIN32 do
    private proc localtime:&time_t * &tm = "localtime_s($2,$1);";
  else
    private proc localtime:&time_t * &tm = "localtime_r($1,$2);";
  done
    fun localtime (var t:time_t) :tm =
    {
      var atm : tm; localtime (&t, &atm);
      return atm;
    }
  
    header """
      string asctime_helper(struct tm const * ti);
    """;
  
  if PLAT_WIN32 do
    body """
      string asctime_helper(struct tm const * ti) {
        int len = 64;
        char *fmted = (char*) malloc(sizeof(char)*64);
        asctime_s(fmted,64,ti);
        string s = string(fmted);
        free(fmted);
        return s;
      }
    """;
  else
    body """
      string asctime_helper(struct tm const * ti) {
        int len = 64;
        char *fmted = (char*) malloc(sizeof(char)*64);
        asctime_r(ti,fmted);
        string s = string(fmted);
        free(fmted);
        return s;
      }
    """;
  done
  
    private fun asctime:&tm -> string = "asctime_helper($1)";
    fun asctime (var t:tm) : string => asctime (&t);
  
    header """
      string strftime_helper(const char *pat,    const struct tm * ti);
    """;
  
    body """
      string strftime_helper(const char *pat,    const struct tm * ti) {
        int len = 64;
        char *fmted = (char*) malloc(sizeof(char)*64);
        strftime(fmted,len,pat,ti);
        string s = string(fmted);
        free(fmted);
        return s;
      }
    """;
  
    private fun strftime: string * &tm -> string = "strftime_helper(($1.c_str()),$2)";
    fun strftime (fmt: string, var t: tm ) :string =
    {
       return strftime (fmt, &t);
    }
  
    fun rfc1123_date (dt:&tm) => strftime("%a, %d %b %Y %H:%M:%S %Z",dt);
    fun rfc1123_date (dt:tm) => strftime("%a, %d %b %Y %H:%M:%S %Z",dt);
  
    fun rfc1123_date () = {
      var time_epoch_seconds = time_t();
      var tm_struct : tm;
      gmtime(&time_epoch_seconds, &tm_struct);
      return rfc1123_date(&tm_struct);
    }
  
    fun hour() => 3600;
  
    fun day() => 86400;
    fun expires_seconds_from_now(seconds:int) ={
      var time_epoch_seconds = time_t() +seconds;
      var tm_struct : tm;
      gmtime(&time_epoch_seconds, &tm_struct);
     return rfc1123_date (&tm_struct);
   }
  
  }