MCPcopy Create free account
hub / github.com/PageBot/PageBot / __init__

Method __init__

Lib/pagebot/toolbox/dating.py:530–621  ·  view source on GitHub ↗
(self, year=0, month=0, day=0, hour=0, minute=0, second=0, microSecond=0, tz=None,
        dt=None, date=None, time=None, week=None, trimvalues=True, mtime=None)

Source from the content-addressed store, hash-verified

528 fullMonthNames = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
529
530 def __init__(self, year=0, month=0, day=0, hour=0, minute=0, second=0, microSecond=0, tz=None,
531 dt=None, date=None, time=None, week=None, trimvalues=True, mtime=None):
532
533 if dt is not None: # If datetime object, just store it.
534 # Assume that dt is of type date string. Direct init from existing datetime
535 self.datetime = dt
536 else:
537 if date == 'now':
538 self.datetime = datetime.datetime.now()
539 return
540
541 if date is not None:
542 if isinstance(date, str):
543 # Could be one of the follovwing formats
544 # YYYY-MM-DD HH:MM:SS
545 stamp = re.compile(r'(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)([\-\+]\d+)?')
546 m = stamp.match(date)
547 if m:
548 year = int(m.group(1))
549 month = int(m.group(2))
550 day = int(m.group(3))
551 hour = int(m.group(4))
552 minute = int(m.group(5))
553 second = int(m.group(6))
554 #@# tz must be a tzinfo object, not an integer, leave it as None for now.
555 #tz = int(m.group(7) or tz)
556 else:
557 try:
558 if '.' in date or '/' in date:
559 date = date.replace('.', '-').replace('/', '-')
560 date = date.split(' ')[0] # Skip possible time part of date input
561 year, month, day = date.split('-')
562 if int(day) > int(year): # If notation 25-03-2007, then swap day and year
563 year, day = day, year
564 except Exception as exc:
565 raise ValueError('[datetime] Wrong date format "%s"' % date) from exc
566 else:
567 # If date is an integer .... format: YYYYMMDD
568 d = str(date)
569 year, month, day = d[:4], d[4:6], d[6:]
570
571 if mtime is not None:
572 # Evaluate the number of seconds since the beginning of time
573 tt = localtime(mtime)
574 year = tt.tm_year
575 month = tt.tm_mon
576 day = tt.tm_mday
577 hour = tt.tm_hour
578 minute = tt.tm_min
579 second = tt.tm_sec
580
581 if time is not None:
582 time = time.split(' ')[-1] # Skip possible date part of the time input
583 timeParts = time.split(':')
584 if len(timeParts) == 2:
585 hour, minute = timeParts
586 second = 0
587 elif len(timeParts) == 3:

Callers

nothing calls this directly

Calls 2

monthDaysFunction · 0.85
matchMethod · 0.80

Tested by

no test coverage detected