How to use the js2py.constructors.jsdate.PyJsDate function in Js2Py

To help you get started, we’ve selected a few Js2Py examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PiotrDabkowski / Js2Py / js2py / constructors / jsdate.py View on Github external
l = len(args)
    dt = args[2].to_number() if l > 2 else Js(1)
    h = args[3].to_number() if l > 3 else Js(0)
    mi = args[4].to_number() if l > 4 else Js(0)
    sec = args[5].to_number() if l > 5 else Js(0)
    mili = args[6].to_number() if l > 6 else Js(0)
    if not y.is_nan() and 0 <= y.value <= 99:
        y = y + Js(1900)
    t = TimeClip(
        LocalToUTC(MakeDate(MakeDay(y, m, dt), MakeTime(h, mi, sec, mili))))
    return PyJsDate(t, prototype=DatePrototype)


Date.create = date_constructor

DatePrototype = PyJsDate(float('nan'), prototype=ObjectPrototype)


def check_date(obj):
    if obj.Class != 'Date':
        raise MakeError('TypeError', 'this is not a Date object')


class DateProto:
    def toString():
        check_date(this)
        if this.value is NaN:
            return 'Invalid Date'
        offset = (UTCToLocal(this.value) - this.value) // msPerHour
        return this.local_strftime(
            '%a %b %d %Y %H:%M:%S GMT') + '%s00 (%s)' % (pad(
                offset, 2, True), GetTimeZoneName(this.value))
github PiotrDabkowski / Js2Py / js2py / constructors / jsdate.py View on Github external
def now():
    return PyJsDate(int(time.time() * 1000), prototype=DatePrototype)
github PiotrDabkowski / Js2Py / js2py / constructors / jsdate.py View on Github external
def date_constructor2(*args):
    y = args[0].to_number()
    m = args[1].to_number()
    l = len(args)
    dt = args[2].to_number() if l > 2 else Js(1)
    h = args[3].to_number() if l > 3 else Js(0)
    mi = args[4].to_number() if l > 4 else Js(0)
    sec = args[5].to_number() if l > 5 else Js(0)
    mili = args[6].to_number() if l > 6 else Js(0)
    if not y.is_nan() and 0 <= y.value <= 99:
        y = y + Js(1900)
    t = TimeClip(
        LocalToUTC(MakeDate(MakeDay(y, m, dt), MakeTime(h, mi, sec, mili))))
    return PyJsDate(t, prototype=DatePrototype)
github PiotrDabkowski / Js2Py / js2py / constructors / jsdate.py View on Github external
def date_constructor1(value):
    v = value.to_primitive()
    if v._type() == 'String':
        v = parse_date(v.value)
    else:
        v = v.to_int()
    return PyJsDate(TimeClip(v), prototype=DatePrototype)
github PiotrDabkowski / Js2Py / js2py / constructors / jsdate.py View on Github external
def parse(string):
    return PyJsDate(
        TimeClip(parse_date(string.to_string().value)),
        prototype=DatePrototype)