How to use the arrow.parser function in arrow

To help you get started, we’ve selected a few arrow 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 crsmithdev / arrow / tests / parser_tests.py View on Github external
def test_english(self):
        parser_ = parser.DateTimeParser("en_us")

        self.assertEqual(
            parser_.parse("January 1st, 2013", "MMMM Do, YYYY"), datetime(2013, 1, 1)
        )
        self.assertEqual(
            parser_.parse("January 2nd, 2013", "MMMM Do, YYYY"), datetime(2013, 1, 2)
        )
        self.assertEqual(
            parser_.parse("January 3rd, 2013", "MMMM Do, YYYY"), datetime(2013, 1, 3)
        )
        self.assertEqual(
            parser_.parse("January 4th, 2013", "MMMM Do, YYYY"), datetime(2013, 1, 4)
        )
        self.assertEqual(
            parser_.parse("January 11th, 2013", "MMMM Do, YYYY"), datetime(2013, 1, 11)
        )
github Geotab / mygeotab-python / mygeotab / serializers.py View on Github external
def object_deserializer(obj):
    """Helper to deserialize a raw result dict into a proper dict.

    :param obj: The dict.
    """
    for key, val in obj.items():
        if isinstance(val, six.string_types) and DATETIME_REGEX.search(val):
            try:
                obj[key] = dates.localize_datetime(arrow.get(val).datetime)
            except (ValueError, arrow.parser.ParserError):
                obj[key] = val
    return obj
github crsmithdev / arrow / arrow / arrow.py View on Github external
def _get_tzinfo(tz_expr):

        if tz_expr is None:
            return dateutil_tz.tzutc()
        if isinstance(tz_expr, dt_tzinfo):
            return tz_expr
        else:
            try:
                return parser.TzinfoParser.parse(tz_expr)
            except parser.ParserError:
                raise ValueError("'{}' not recognized as a timezone".format(tz_expr))
github csirtgadgets / bearded-avenger / cif / utils / znltk.py View on Github external
indicator = Indicator()
        for e in cols:
            if e:
                try:
                    i = resolve_itype(e)
                    if i:
                        indicator.indicator = e
                        indicator.itype = i
                except NotImplementedError:
                    pass

                try:
                    ts = arrow.get(e)
                    if ts:
                        indicator.lasttime = ts.datetime
                except (arrow.parser.ParserError, UnicodeDecodeError):
                    pass

                if e in top:
                    indicator.tags = [e]

        if indicator.itype and indicator.indicator:
            ret.append(indicator)

    return ret
github Netflix-Skunkworks / stethoscope / stethoscope / plugins / sources / jamf / base.py View on Github external
'serial': 'serial_number',
      'name': 'name',
    }))

    data.update(stethoscope.utils.copy_partial_dict(computer['hardware'], {
      'os': 'os_name',
      'os_version': 'os_version',
    }))

    email = computer.get('location', {}).get('email_address')
    if email is not None:
      data['email'] = email

    try:
      last_updated = arrow.get(computer['general']['report_date_utc'])
    except arrow.parser.ParserError:
      last_updated = None

    data['last_sync'] = last_updated

    # PRACTICES
    data['practices'] = dict()
    data['practices']['encryption'] = inject_last_updated(self._check_encryption(raw), last_updated)
    data['practices']['uptodate'] = inject_last_updated(self._check_uptodate(raw), last_updated)
    data['practices']['autoupdate'] = inject_last_updated(self._check_autoupdate(attributes),
        last_updated)

    data['software'] = {'last_scan_date': last_updated}
    data['software']['installed'] = [self._normalize_software_entry(entry) for entry in
        raw['computer']['software']['applications']]
    data['software']['services'] = [{'name': service} for service in
        raw['computer']['software']['running_services']]
github crsmithdev / arrow / arrow / factory.py View on Github external
arg_count = len(args)
        locale = kwargs.pop("locale", "en_us")
        tz = kwargs.get("tzinfo", None)

        # if kwargs given, send to constructor unless only tzinfo provided
        if len(kwargs) > 1:
            arg_count = 3

        # tzinfo kwarg is not provided
        if len(kwargs) == 1 and tz is None:
            arg_count = 3

        # () -> now, @ utc.
        if arg_count == 0:
            if isstr(tz):
                tz = parser.TzinfoParser.parse(tz)
                return self.type.now(tz)

            if isinstance(tz, dt_tzinfo):
                return self.type.now(tz)

            return self.type.utcnow()

        if arg_count == 1:
            arg = args[0]

            # (None) -> now, @ utc.
            if arg is None:
                return self.type.utcnow()

            # try (int, float) -> utc, from timestamp.
            elif not isstr(arg) and is_timestamp(arg):
github crsmithdev / arrow / arrow / arrow.py View on Github external
def _get_tzinfo(tz_expr):

        if tz_expr is None:
            return dateutil_tz.tzutc()
        if isinstance(tz_expr, dt_tzinfo):
            return tz_expr
        else:
            try:
                return parser.TzinfoParser.parse(tz_expr)
            except parser.ParserError:
                raise ValueError("'{}' not recognized as a timezone".format(tz_expr))
github PlaidWeb / Publ / publ / entry.py View on Github external
'status': model.PublishStatus[entry.get('Status', 'SCHEDULED').upper()].value,
        'entry_type': entry.get('Entry-Type', ''),
        'slug_text': slugify.slugify(
            entry.get('Slug-Text',
                      markdown.render_title(title, markup=False, smartquotes=False))),
        'redirect_url': entry.get('Redirect-To', ''),
        'title': title,
        'sort_title': entry.get('Sort-Title', title),
        'canonical_path': entry.get('Path-Canonical', '')
    }

    entry_date = None
    if 'Date' in entry:
        try:
            entry_date = arrow.get(entry['Date'], tzinfo=config.timezone)
        except arrow.parser.ParserError:
            entry_date = None
    if entry_date is None:
        del entry['Date']
        entry_date = arrow.get(
            os.stat(fullpath).st_ctime).to(config.timezone)
        entry['Date'] = entry_date.format()
        fixup_needed = True

    if 'Last-Modified' in entry:
        last_modified_str = entry['Last-Modified']
        try:
            last_modified = arrow.get(
                last_modified_str, tzinfo=config.timezone)
        except arrow.parser.ParserError:
            last_modified = arrow.get()
            del entry['Last-Modified']
github OpenHumans / open-humans / private_sharing / forms.py View on Github external
def validate_date(date):
            try:
                arrow.get(date)
            except arrow.parser.ParserError:
                raise forms.ValidationError("Dates must be in ISO 8601 format")