# -*- coding: utf-8 -*- """ Test LDAP """ import datetime import logging import sys import dateutil.tz import pytz from mylib.ldap import format_datetime,format_date, parse_datetime, parse_date from mylib.scripts.helpers import get_opts_parser from mylib.scripts.helpers import init_logging log = logging.getLogger('mylib.scripts.ldap_test') def main(argv=None): #pylint: disable=too-many-locals,too-many-statements """ Script main """ if argv is None: argv = sys.argv[1:] # Options parser parser = get_opts_parser(just_try=True) options = parser.parse_args() now = datetime.datetime.now().replace(tzinfo=dateutil.tz.tzlocal()) print("Now = %s" % now) datestring_now = format_datetime(now) print("format_datetime : %s" % datestring_now) print("format_datetime (from_timezone=utc) : %s" % format_datetime(now.replace(tzinfo=None), from_timezone=pytz.utc)) print("format_datetime (from_timezone=local) : %s" % format_datetime(now.replace(tzinfo=None), from_timezone=dateutil.tz.tzlocal())) print("format_datetime (from_timezone='local') : %s" % format_datetime(now.replace(tzinfo=None), from_timezone='local')) print("format_datetime (from_timezone=Paris) : %s" % format_datetime(now.replace(tzinfo=None), from_timezone='Europe/Paris')) print("format_datetime (to_timezone=utc) : %s" % format_datetime(now, to_timezone=pytz.utc)) print("format_datetime (to_timezone=local) : %s" % format_datetime(now, to_timezone=dateutil.tz.tzlocal())) print("format_datetime (to_timezone='local') : %s" % format_datetime(now, to_timezone='local')) print("format_datetime (to_timezone=Tokyo) : %s" % format_datetime(now, to_timezone='Asia/Tokyo')) print("format_datetime (naive=True) : %s" % format_datetime(now, naive=True)) print("format_date : %s" % format_date(now)) print("format_date (from_timezone=utc) : %s" % format_date(now.replace(tzinfo=None), from_timezone=pytz.utc)) print("format_date (from_timezone=local) : %s" % format_date(now.replace(tzinfo=None), from_timezone=dateutil.tz.tzlocal())) print("format_date (from_timezone='local') : %s" % format_date(now.replace(tzinfo=None), from_timezone='local')) print("format_date (from_timezone=Paris) : %s" % format_date(now.replace(tzinfo=None), from_timezone='Europe/Paris')) print("format_date (to_timezone=utc) : %s" % format_date(now, to_timezone=pytz.utc)) print("format_date (to_timezone=local) : %s" % format_date(now, to_timezone=dateutil.tz.tzlocal())) print("format_date (to_timezone='local') : %s" % format_date(now, to_timezone='local')) print("format_date (to_timezone=Tokyo) : %s" % format_date(now, to_timezone='Asia/Tokyo')) print("format_date (naive=True) : %s" % format_date(now, naive=True)) print("parse_datetime : %s" % parse_datetime(datestring_now)) print("parse_datetime (default_timezone=utc) : %s" % parse_datetime(datestring_now[0:-1], default_timezone=pytz.utc)) print("parse_datetime (default_timezone=local) : %s" % parse_datetime(datestring_now[0:-1], default_timezone=dateutil.tz.tzlocal())) print("parse_datetime (default_timezone='local') : %s" % parse_datetime(datestring_now[0:-1], default_timezone='local')) print("parse_datetime (default_timezone=Paris) : %s" % parse_datetime(datestring_now[0:-1], default_timezone='Europe/Paris')) print("parse_datetime (to_timezone=utc) : %s" % parse_datetime(datestring_now, to_timezone=pytz.utc)) print("parse_datetime (to_timezone=local) : %s" % parse_datetime(datestring_now, to_timezone=dateutil.tz.tzlocal())) print("parse_datetime (to_timezone='local') : %s" % parse_datetime(datestring_now, to_timezone='local')) print("parse_datetime (to_timezone=Tokyo) : %s" % parse_datetime(datestring_now, to_timezone='Asia/Tokyo')) print("parse_datetime (naive=True) : %s" % parse_datetime(datestring_now, naive=True)) print("parse_date : %s" % parse_date(datestring_now)) print("parse_date (default_timezone=utc) : %s" % parse_date(datestring_now[0:-1], default_timezone=pytz.utc)) print("parse_date (default_timezone=local) : %s" % parse_date(datestring_now[0:-1], default_timezone=dateutil.tz.tzlocal())) print("parse_date (default_timezone='local') : %s" % parse_date(datestring_now[0:-1], default_timezone='local')) print("parse_date (default_timezone=Paris) : %s" % parse_date(datestring_now[0:-1], default_timezone='Europe/Paris')) print("parse_date (to_timezone=utc) : %s" % parse_date(datestring_now, to_timezone=pytz.utc)) print("parse_date (to_timezone=local) : %s" % parse_date(datestring_now, to_timezone=dateutil.tz.tzlocal())) print("parse_date (to_timezone='local') : %s" % parse_date(datestring_now, to_timezone='local')) print("parse_date (to_timezone=Tokyo) : %s" % parse_date(datestring_now, to_timezone='Asia/Tokyo')) print("parse_date (naive=True) : %s" % parse_date(datestring_now, naive=True))