How to use the parsedatetime.parsedatetime_consts.Calendar function in parsedatetime

To help you get started, we’ve selected a few parsedatetime 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 jrnl-org / jrnl / features / steps / core.py View on Github external
try:
    import parsedatetime.parsedatetime_consts as pdt
except ImportError:
    import parsedatetime as pdt
import time
import os
import json
import yaml
import keyring
import tzlocal
import shlex
import sys

consts = pdt.Constants(usePyICU=False)
consts.DOWParseStyle = -1  # Prefers past weekdays
CALENDAR = pdt.Calendar(consts)


class TestKeyring(keyring.backend.KeyringBackend):
    """A test keyring that just stores its values in a hash"""

    priority = 1
    keys = defaultdict(dict)

    def set_password(self, servicename, username, password):
        self.keys[servicename][username] = password

    def get_password(self, servicename, username):
        return self.keys[servicename].get(username)

    def delete_password(self, servicename, username):
        self.keys[servicename][username] = None
github jrnl-org / jrnl / jrnl / time.py View on Github external
from datetime import datetime
from dateutil.parser import parse as dateparse

try:
    import parsedatetime.parsedatetime_consts as pdt
except ImportError:
    import parsedatetime as pdt

FAKE_YEAR = 9999
DEFAULT_FUTURE = datetime(FAKE_YEAR, 12, 31, 23, 59, 59)
DEFAULT_PAST = datetime(FAKE_YEAR, 1, 1, 0, 0)

consts = pdt.Constants(usePyICU=False)
consts.DOWParseStyle = -1  # "Monday" will be either today or the last Monday
CALENDAR = pdt.Calendar(consts)


def parse(
    date_str, inclusive=False, default_hour=None, default_minute=None, bracketed=False
):
    """Parses a string containing a fuzzy date and returns a datetime.datetime object"""
    if not date_str:
        return None
    elif isinstance(date_str, datetime):
        return date_str

    # Don't try to parse anything with 6 or less characters and was parsed from the existing journal.
    # It's probably a markdown footnote
    if len(date_str) <= 6 and bracketed:
        return None