<commit_before>#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Copyright (c) 2016 Mozilla Corporation
# Contributors:
# <NAME> <<EMAIL>>

import pytz
from datetime import datetime
from dateutil.parser import parse
from tokenize import generate_tokens
try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO
import os

def toUTC(suspectedDate, localTimeZone=None):
    '''Anything => UTC date. Magic.'''
    if (localTimeZone == None):
        if (len(os.environ['TZ']) > 0):
            localTimeZone = os.environ['TZ']
        else:
            try:
                localTimeZone = '/'.join(os.path.realpath('/etc/localtime').split('/')[-2:])
            except:
                localTimeZone = 'UTC'
    utc = pytz.UTC
    objDate = None
    if (type(suspectedDate) == str):
        objDate = parse(suspectedDate, fuzzy=True)
    elif (type(suspectedDate) == datetime):
        objDate=suspectedDate

    if (objDate.tzinfo is None):
        try:
            objDate=pytz.timezone(localTimeZone).localize(objDate)
        except pytz.exceptions.UnknownTimeZoneError:
            #Meh if all fails, I decide you're UTC!
            objDate=pytz.timezone('UTC').localize(objDate)
        objDate=utc.normalize(objDate)
    else:
        objDate=utc.normalize(objDate)
    if (objDate is not None):
        objDate=utc.normalize(objDate)<commit_msg>Default utc date to now<commit_after>#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Copyright (c) 2016 Mozilla Corporation
# Contributors:
# <NAME> <<EMAIL>>

import pytz
from datetime import datetime
from dateutil.parser import parse
from tokenize import generate_tokens
try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO
import os

def toUTC(suspectedDate=datetime.now(), localTimeZone=None):
    '''Anything => UTC date. Magic.'''
    if (localTimeZone == None):
        if (len(os.environ['TZ']) > 0):
            localTimeZone = os.environ['TZ']
        else:
            try:
                localTimeZone = '/'.join(os.path.realpath('/etc/localtime').split('/')[-2:])
            except:
                localTimeZone = 'UTC'
    utc = pytz.UTC
    objDate = None
    if (type(suspectedDate) == str):
        objDate = parse(suspectedDate, fuzzy=True)
    elif (type(suspectedDate) == datetime):
        objDate=suspectedDate

    if (objDate.tzinfo is None):
        try:
            objDate=pytz.timezone(localTimeZone).localize(objDate)
        except pytz.exceptions.UnknownTimeZoneError:
            #Meh if all fails, I decide you're UTC!
            objDate=pytz.timezone('UTC').localize(objDate)
        objDate=utc.normalize(objDate)
    else:
        objDate=utc.normalize(objDate)
    if (objDate is not None):
        objDate=utc.normalize(objDate)
{'fraction_non_alphanumeric': 0.11291866028708133, 'fraction_numerical': 0.006379585326953748, 'mean_word_length': 2.778313253012048, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1939868', 'n_tokens_mistral': 1004, 'n_tokens_neox': 960, 'n_words': 269}