Exemplo n.º 1
0
def strftime(format, tt=None):  # pylint: disable=missing-docstring,redefined-builtin
  t = Unix(int(mktime(tt)), 0) if tt else Now()
  ret = []
  prev, n = 0, format.find('%', 0, -1)
  while n != -1:
    ret.append(format[prev:n])
    next_ch = format[n + 1]
    c = _strftime_directive_map.get(next_ch)
    if c is NotImplemented:
      raise NotImplementedError('Code: %' + next_ch + ' not yet supported')
    if c:
      ret.append(t.Format(c))
    else:
      ret.append(format[n:n+2])
    n += 2
    prev, n = n, format.find('%', n, -1)
  ret.append(format[prev:])
  return ''.join(ret)
Exemplo n.º 2
0
 def seed(self, a=None):
   """Seed the golang.math.rand generator."""
   if a is None:
     a = Now().UnixNano()
   Seed(a)
Exemplo n.º 3
0
def localtime(seconds=None):
  t = (Unix(seconds, 0) if seconds else Now()).Local()
  return struct_time((t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(),
                      t.Second(), (t.Weekday() + 6) % 7, t.YearDay(), 0))
Exemplo n.º 4
0
def time():
  return float(Now().UnixNano()) / Second
Exemplo n.º 5
0
def time():
  return float(Now().UnixNano()) / Second


def strftime(format, tt=None):  # pylint: disable=missing-docstring,redefined-builtin
  t = Unix(int(mktime(tt)), 0) if tt else Now()
  ret = []
  prev, n = 0, format.find('%', 0, -1)
  while n != -1:
    ret.append(format[prev:n])
    next_ch = format[n + 1]
    c = _strftime_directive_map.get(next_ch)
    if c is NotImplemented:
      raise NotImplementedError('Code: %' + next_ch + ' not yet supported')
    if c:
      ret.append(t.Format(c))
    else:
      ret.append(format[n:n+2])
    n += 2
    prev, n = n, format.find('%', n, -1)
  ret.append(format[prev:])
  return ''.join(ret)


# TODO: Calculate real value for daylight saving.
daylight = 0

# TODO: Use local DST instead of ''.
tzname = (Now().Zone()[0], '')