77 lines
4.8 KiB
Python
77 lines
4.8 KiB
Python
# -*- 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()
|
|
|
|
# Initialize logs
|
|
init_logging(options, 'Test LDAP helpers')
|
|
|
|
now = datetime.datetime.now().replace(tzinfo=dateutil.tz.tzlocal())
|
|
print(f'Now = {now}')
|
|
|
|
datestring_now = format_datetime(now)
|
|
print(f'format_datetime : {datestring_now}')
|
|
print(f'format_datetime (from_timezone=utc) : {format_datetime(now.replace(tzinfo=None), from_timezone=pytz.utc)}')
|
|
print(f'format_datetime (from_timezone=local) : {format_datetime(now.replace(tzinfo=None), from_timezone=dateutil.tz.tzlocal())}')
|
|
print(f'format_datetime (from_timezone=local) : {format_datetime(now.replace(tzinfo=None), from_timezone="local")}')
|
|
print(f'format_datetime (from_timezone=Paris) : {format_datetime(now.replace(tzinfo=None), from_timezone="Europe/Paris")}')
|
|
print(f'format_datetime (to_timezone=utc) : {format_datetime(now, to_timezone=pytz.utc)}')
|
|
print(f'format_datetime (to_timezone=local) : {format_datetime(now, to_timezone=dateutil.tz.tzlocal())}')
|
|
print(f'format_datetime (to_timezone=local) : {format_datetime(now, to_timezone="local")}')
|
|
print(f'format_datetime (to_timezone=Tokyo) : {format_datetime(now, to_timezone="Asia/Tokyo")}')
|
|
print(f'format_datetime (naive=True) : {format_datetime(now, naive=True)}')
|
|
|
|
print(f'format_date : {format_date(now)}')
|
|
print(f'format_date (from_timezone=utc) : {format_date(now.replace(tzinfo=None), from_timezone=pytz.utc)}')
|
|
print(f'format_date (from_timezone=local) : {format_date(now.replace(tzinfo=None), from_timezone=dateutil.tz.tzlocal())}')
|
|
print(f'format_date (from_timezone=local) : {format_date(now.replace(tzinfo=None), from_timezone="local")}')
|
|
print(f'format_date (from_timezone=Paris) : {format_date(now.replace(tzinfo=None), from_timezone="Europe/Paris")}')
|
|
print(f'format_date (to_timezone=utc) : {format_date(now, to_timezone=pytz.utc)}')
|
|
print(f'format_date (to_timezone=local) : {format_date(now, to_timezone=dateutil.tz.tzlocal())}')
|
|
print(f'format_date (to_timezone=local) : {format_date(now, to_timezone="local")}')
|
|
print(f'format_date (to_timezone=Tokyo) : {format_date(now, to_timezone="Asia/Tokyo")}')
|
|
print(f'format_date (naive=True) : {format_date(now, naive=True)}')
|
|
|
|
print(f'parse_datetime : {parse_datetime(datestring_now)}')
|
|
print(f'parse_datetime (default_timezone=utc) : {parse_datetime(datestring_now[0:-1], default_timezone=pytz.utc)}')
|
|
print(f'parse_datetime (default_timezone=local) : {parse_datetime(datestring_now[0:-1], default_timezone=dateutil.tz.tzlocal())}')
|
|
print(f'parse_datetime (default_timezone=local) : {parse_datetime(datestring_now[0:-1], default_timezone="local")}')
|
|
print(f'parse_datetime (default_timezone=Paris) : {parse_datetime(datestring_now[0:-1], default_timezone="Europe/Paris")}')
|
|
print(f'parse_datetime (to_timezone=utc) : {parse_datetime(datestring_now, to_timezone=pytz.utc)}')
|
|
print(f'parse_datetime (to_timezone=local) : {parse_datetime(datestring_now, to_timezone=dateutil.tz.tzlocal())}')
|
|
print(f'parse_datetime (to_timezone=local) : {parse_datetime(datestring_now, to_timezone="local")}')
|
|
print(f'parse_datetime (to_timezone=Tokyo) : {parse_datetime(datestring_now, to_timezone="Asia/Tokyo")}')
|
|
print(f'parse_datetime (naive=True) : {parse_datetime(datestring_now, naive=True)}')
|
|
|
|
print(f'parse_date : {parse_date(datestring_now)}')
|
|
print(f'parse_date (default_timezone=utc) : {parse_date(datestring_now[0:-1], default_timezone=pytz.utc)}')
|
|
print(f'parse_date (default_timezone=local) : {parse_date(datestring_now[0:-1], default_timezone=dateutil.tz.tzlocal())}')
|
|
print(f'parse_date (default_timezone=local) : {parse_date(datestring_now[0:-1], default_timezone="local")}')
|
|
print(f'parse_date (default_timezone=Paris) : {parse_date(datestring_now[0:-1], default_timezone="Europe/Paris")}')
|
|
print(f'parse_date (to_timezone=utc) : {parse_date(datestring_now, to_timezone=pytz.utc)}')
|
|
print(f'parse_date (to_timezone=local) : {parse_date(datestring_now, to_timezone=dateutil.tz.tzlocal())}')
|
|
print(f'parse_date (to_timezone=local) : {parse_date(datestring_now, to_timezone="local")}')
|
|
print(f'parse_date (to_timezone=Tokyo) : {parse_date(datestring_now, to_timezone="Asia/Tokyo")}')
|
|
print(f'parse_date (naive=True) : {parse_date(datestring_now, naive=True)}')
|