<commit_before>import datetime
import pytz
import JSPy as js

class DateJS():
    def __init__(self, JS_STRING, y=0, m=0, d=0, h=0, minute=0, s=0, ms=0, tzo=0):
        self.YEAR = y
        self.MONTH = m + 1
        self.DATE = d
        self.HOUR = h
        self.MINUTE = minute
        self.SECOND = s
        self.MILLISECONDS = ms
        self.OFFSET = int(tzo)
        self.TZ = None
        self.TZ_SIMPLE = None
        self.TZ_CUSTOM = None
        self.JS_TIME = JS_STRING
        self.PYTIME = datetime.datetime.now()
        self.PYTIME_SIMPLE = datetime.datetime.now()
        self.PYTIME_CUSTOM = datetime.datetime.now()
        self.CUSTOM_TIMEZONES = []
        self.jsFunction = None
        self.result = None
        if self.YEAR == 0:
            self.runJSFunction()
        self.setAllValues()

    def runJSFunction(self):
        self.jsFunction = """
                function run(x){
                    var date = new Date(x);
                    console.log(date.getFullYear());
                    console.log(date.getMonth());
                    console.log(date.getDate());
                    console.log(date.getHours());
                    console.log(date.getMinutes());
                    console.log(date.getSeconds());
                    console.log(date.getMilliseconds());
                    console.log(date.getTimezoneOffset());
                }
            """
        funcCall = "run('" + self.JS_TIME + "');"
        self.result = js.exec(self.jsFunction + funcCall).splitlines()
        self.result = [int(k) for k in self.result]
        return

    def setAllValues(self):
        if not self.result == None:
            self.setYear()
            self.setMonth()
            self.setDate()
            self.setHour()
            self.setMinute()
            self.setSecond()
            self.setMillisecond()
        self.setTZ()

    def getTime(self):
        self.PYTIME = self.PYTIME.replace(year=self.YEAR, month=self.MONTH, day=self.DATE, hour=self.HOUR, minute=self.MINUTE, second=self.SECOND, microsecond=self.MILLISECONDS, tzinfo=pytz.timezone(self.TZ))
        return self.PYTIME

    def getSimpleTime(self):
        self.PYTIME_SIMPLE = self.PYTIME_SIMPLE.replace(year=self.YEAR, month=self.MONTH, day=self.DATE, hour=self.HOUR, minute=self.MINUTE, second=self.SECOND, microsecond=self.MILLISECONDS, tzinfo=pytz.timezone(self.TZ_SIMPLE))
        return self.PYTIME_SIMPLE

    def getCustomTime(self):
        self.PYTIME_CUSTOM = self.PYTIME_CUSTOM.replace(year=self.YEAR, month=self.MONTH, day=self.DATE, hour=self.HOUR, minute=self.MINUTE, second=self.SECOND, microsecond=self.MILLISECONDS, tzinfo=pytz.timezone(self.TZ_CUSTOM))
        return self.PYTIME_CUSTOM

    def getYear(self):
        return self.YEAR

    def setYear(self):
        self.YEAR = self.result[0]
        return

    def getMonth(self):
        return self.MONTH

    def setMonth(self):
        self.MONTH = self.result[1] + 1 # This +1 moves month numbers from 0-11 to 1-12
        return

    def getDate(self):
        return self.DATE

    def setDate(self):
        self.DATE = self.result[2]
        return

    def getHours(self):
        return self.HOUR

    def setHour(self):
        self.HOUR = self.result[3]
        return

    def getMinutes(self):
        return self.MINUTE

    def setMinute(self):
        self.MINUTE = self.result[4]
        return

    def getSeconds(self):
        return self.SECOND

    def setSecond(self):
        self.SECOND = self.result[5]
        return

    def getMilliseconds(self):
        return self.MILLISECONDS

    def setMillisecond(self):
        self.MILLISECONDS = self.result[6]
        return

    def getTimezone(self):
        return self.TZ

    def getSimpleTimezone(self):
        return self.TZ_SIMPLE

    def getCustomTimezone(self):
        return self.TZ_CUSTOM

    def setTZ(self):
        if not self.result == None:
            self.OFFSET = self.result[7]
        self.OFFSET = self.offsetFormat()
        sorted_tzs = self.allTimezones()
        for zone in sorted_tzs:
            if self.OFFSET in zone[1]:
                self.TZ = zone[0]
                break
        simple_tzs = self.basicTimezones()
        for z in simple_tzs:
            if self.OFFSET in z[1]:
                self.TZ_SIMPLE = z[0]
                break
        custom_tzs = self.CUSTOM_TIMEZONES
        if custom_tzs == []:
            return
        for w in custom_tzs:
            if self.OFFSET in w[1]:
                self.TZ_CUSTOM = w[0]
                return
        raise Exception("No Timezone Found!")

    def offsetFormat(self):
        west = True<commit_msg>Automatically parse through js date and fill in required fields<commit_after>import datetime
import pytz
import JSPy as js

class DateJS():
    def __init__(self, JS_STRING, convert=False):
        self.YEAR = 0
        self.MONTH = 0
        self.DATE = 0
        self.HOUR = 0
        self.MINUTE = 0
        self.SECOND = 0
        self.MILLISECONDS = 0
        self.OFFSET = 0
        self.TZ = None
        self.TZ_SIMPLE = None
        self.TZ_CUSTOM = None
        self.JS_TIME = JS_STRING
        self.PYTIME = datetime.datetime.now()
        self.PYTIME_SIMPLE = datetime.datetime.now()
        self.PYTIME_CUSTOM = datetime.datetime.now()
        self.CUSTOM_TIMEZONES = []
        self.jsFunction = None
        self.result = None
        self.MONTH_ABBR_LIST = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        if convert:
            self.runJSFunction()
        else:
            self.parseValues()
        self.setAllValues()

    def parseValues(self):
        arr = self.JS_TIME.split()
        self.YEAR = int(arr[3])
        self.MONTH = self.MONTH_ABBR_LIST.index(arr[1])
        self.DATE = int(arr[2])
        time = arr[4].split(":")
        self.HOUR = int(time[0])
        self.MINUTE = int(time[1])
        self.SECOND = int(time[2])
        offset_string = ''.join(c for c in arr[5] if c.isdigit())
        self.OFFSET = int(offset_string[:2]) * 60 + int(offset_string[2:])

    def runJSFunction(self):
        self.jsFunction = """
                function run(x){
                    var date = new Date(x);
                    console.log(date.getFullYear());
                    console.log(date.getMonth());
                    console.log(date.getDate());
                    console.log(date.getHours());
                    console.log(date.getMinutes());
                    console.log(date.getSeconds());
                    console.log(date.getMilliseconds());
                    console.log(date.getTimezoneOffset());
                }
            """
        funcCall = "run('" + self.JS_TIME + "');"
        self.result = js.exec(self.jsFunction + funcCall).splitlines()
        self.result = [int(k) for k in self.result]
        return

    def setAllValues(self):
        if not self.result == None:
            self.setYear()
            self.setMonth()
            self.setDate()
            self.setHour()
            self.setMinute()
            self.setSecond()
            self.setMillisecond()
        self.setTZ()

    def getTime(self):
        self.PYTIME = self.PYTIME.replace(year=self.YEAR, month=self.MONTH, day=self.DATE, hour=self.HOUR, minute=self.MINUTE, second=self.SECOND, microsecond=self.MILLISECONDS, tzinfo=pytz.timezone(self.TZ_SIMPLE))
        return self.PYTIME

    def getFullTime(self):
        self.PYTIME_SIMPLE = self.PYTIME_SIMPLE.replace(year=self.YEAR, month=self.MONTH, day=self.DATE, hour=self.HOUR, minute=self.MINUTE, second=self.SECOND, microsecond=self.MILLISECONDS, tzinfo=pytz.timezone(self.TZ))
        return self.PYTIME_SIMPLE

    def getCustomTime(self):
        self.PYTIME_CUSTOM = self.PYTIME_CUSTOM.replace(year=self.YEAR, month=self.MONTH, day=self.DATE, hour=self.HOUR, minute=self.MINUTE, second=self.SECOND, microsecond=self.MILLISECONDS, tzinfo=pytz.timezone(self.TZ_CUSTOM))
        return self.PYTIME_CUSTOM

    def getYear(self):
        return self.YEAR

    def setYear(self):
        self.YEAR = self.result[0]
        return

    def getMonth(self):
        return self.MONTH

    def setMonth(self):
        self.MONTH = self.result[1] + 1 # This +1 moves month numbers from 0-11 to 1-12
        return

    def getDate(self):
        return self.DATE

    def setDate(self):
        self.DATE = self.result[2]
        return

    def getHours(self):
        return self.HOUR

    def setHour(self):
        self.HOUR = self.result[3]
        return

    def getMinutes(self):
        return self.MINUTE

    def setMinute(self):
        self.MINUTE = self.result[4]
        return

    def getSeconds(self):
        return self.SECOND

    def setSecond(self):
        self.SECOND = self.result[5]
        return

    def getMilliseconds(self):
        return self.MILLISECONDS

    def setMillisecond(self):
        self.MILLISECONDS = self.result[6]
        return

    def getTimezone(self):
        return self.TZ_SIMPLE

    def getFullTimezone(self):
        return self.TZ

    def getCustomTimezone(self):
        return self.TZ_CUSTOM

    def setTZ(self):
        if not self.result == None:
            self.OFFSET = self.result[7]
        self.OFFSET = self.offsetFormat()
        sorted_tzs = self.allTimezones()
        for zone in sorted_tzs:
            if self.OFFSET in zone[1]:
                self.TZ = zone[0]
                break
        simple_tzs = self.basicTimezones()
        for z in simple_tzs:
            if self.OFFSET in z[1]:
                self.TZ_SIMPLE = z[0]
                break
        custom_tzs = self.CUSTOM_TIMEZONES
        if custom_tzs == []:
            return
        for w in custom_tzs:
            if self.OFFSET in w[1]:
                self.TZ_CUSTOM = w[0]
                return
        raise Exception("No Timezone Found!")

    def offsetFormat(self):
        west = True
{'fraction_non_alphanumeric': 0.11128935231602166, 'fraction_numerical': 0.007419290154401444, 'mean_word_length': 1.8929814385150812, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, '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': '2925041', 'n_tokens_mistral': 3283, 'n_tokens_neox': 3144, 'n_words': 624}