pike.git / lib / modules / Val.pmod / module.pmod

version» Context lines:

pike.git/lib/modules/Val.pmod/module.pmod:366:    //! Casting it to float and int return unix-time values.    //! @seealso    //! @[mktime()], @[gmtime()]    protected mixed cast(string to) {    switch (to) {    case "string":    return (nsecs < 0 ? "-" : "") + iso_time(tm());    case "float":    return nsecs / NANOSECONDS.0;    case "int": -  return nsecs / NANOSECONDS; +  return (nsecs - (nsecs < 0 ? NANOSECONDS - 1 : 0)) / NANOSECONDS;    default:    return UNDEFINED;    }    }       protected string _sprintf(int fmt, mapping(string:mixed) params) {    switch (fmt) {    case 's': return (string)this;    default: return sprintf(sprintf("%%*%c", fmt), params, 0);    }
pike.git/lib/modules/Val.pmod/module.pmod:778:       //! @returns    //! The same as @[localtime()], but augmented    //! by an extra member called @expr{nsec@}.    //! @seealso    //! @[localtime()]    public mapping(string:int) tm() {    return localtime((int)this) + (["nsec": nsecs % NANOSECONDS ]);    }    +  //! @seealso +  //! @[System.TM()->strftime()] +  public string(1..255) strftime(string(1..255) format) { +  return System.TM((int)this)->strftime(format); +  } +  +  //! @seealso +  //! @[System.TM()->strptime()] +  public bool strptime(string(1..255) format, string(1..255) data) { +  System.TM t = System.TM(); +  bool ret = t->strptime(format, data); +  if (ret) +  ::create(t->unix_time()); +  return ret; +  } +     //! When cast to string it returns an ISO formatted timestamp    //! that includes daylight-saving and timezone corrections.    protected mixed cast(string to) {    switch (to) {    case "string": {    mapping(string:int) t = tm();    string res = sprintf("%04d-%02d-%02d",    t->year + 1900, t->mon+1, t->mday);    if (t->hour || t->min || t->sec || t->nsec)    res += " " + iso_time(t);
pike.git/lib/modules/Val.pmod/module.pmod:835:    variant protected void create(this_program copy) {    days = [int]copy->days;    }    variant protected void create(Timestamp copy) {    days = copy->nsecs / (24 * 3600 * NANOSECONDS) - (copy->nsecs < 0);    }    variant protected void create(mapping(string:int) tm) {    create(mktime(tm + (["isdst":0, "timezone":0])));    }    variant protected void create(int unix_time) { -  days = unix_time / (24 * 3600); +  days = (unix_time - (unix_time < 0 ? 24 * 3600 -1 : 0)) / (24 * 3600);    }    variant protected void create(float unix_time) {    create((int)unix_time);    }    variant protected void create() {    }       protected mixed `+(mixed that) {    object n = this_program(this);    if (objectp(that)) {
pike.git/lib/modules/Val.pmod/module.pmod:921:    || !zero_type(([object]that)->nsecs)    && days * 24 * 3600 * NANOSECONDS == [int]([object]that)->nsecs)    || intp(that) && (int)this == [int]that    || floatp(that) && (float)this == [float]that;    }       public mapping(string:int) tm() {    return gmtime((int)this);    }    +  //! @seealso +  //! @[System.TM()->strftime()] +  public string(1..255) strftime(string(1..255) format) { +  return System.TM((int)this)->strftime(format); +  } +  +  //! @seealso +  //! @[System.TM()->strptime()] +  public bool strptime(string(1..255) format, string(1..255) data) { +  System.TM t = System.TM(); +  bool ret = t->strptime(format, data); +  if (ret) +  create(t->unix_time()); +  return ret; +  } +     protected mixed cast(string to) {    switch (to) {    case "string": {    mapping(string:int) t = tm();    return sprintf("%04d-%02d-%02d", t->year + 1900, t->mon+1, t->mday);    }    case "float":    return (float)(int)this;    case "int":    return days * 24 * 3600;