How to use the parsedatetime.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 bear / parsedatetime / tests / TestUnits.py View on Github external
def setUp(self):
        self.cal = pdt.Calendar()
        (self.yr, self.mth, self.dy, self.hr,
         self.mn, self.sec, self.wd, self.yd, self.isdst) = time.localtime()
github certbot / certbot / letsencrypt / storage.py View on Github external
def add_time_interval(base_time, interval, textparser=parsedatetime.Calendar()):
    """Parse the time specified time interval, and add it to the base_time

    The interval can be in the English-language format understood by
    parsedatetime, e.g., '10 days', '3 weeks', '6 months', '9 hours', or
    a sequence of such intervals like '6 months 1 week' or '3 days 12
    hours'. If an integer is found with no associated unit, it is
    interpreted by default as a number of days.

    :param datetime.datetime base_time: The time to be added with the interval.
    :param str interval: The time interval to parse.

    :returns: The base_time plus the interpretation of the time interval.
    :rtype: :class:`datetime.datetime`"""

    if interval.strip().isdigit():
        interval += " days"
github MatthiasKauer / tim / tim / timscript.py View on Github external
def parse_engtime(timestr):
#http://stackoverflow.com/questions/4615250/python-convert-relative-date-string-to-absolute-date-stamp
    cal = parsedatetime.Calendar()
    if timestr is None or timestr is "":\
        timestr = 'now'

    #example from here: https://github.com/bear/parsedatetime/pull/60
    ret = cal.parseDT(timestr, tzinfo=local_tz)[0]
    ret_utc = ret.astimezone(pytz.utc)
    # ret = cal.parseDT(timestr, sourceTime=datetime.utcnow())[0]
    return ret_utc
github corpnewt / CorpBot.py / Cogs / Remind.py View on Github external
async def remindme(self, ctx, message : str = None, *, endtime : str = None):
		"""Set a reminder.  If the message contains spaces, it must be wrapped in quotes."""

		if not endtime or not message:
			msg = 'Usage: `{}remindme "[message]" [endtime]`'.format(ctx.prefix)
			await ctx.channel.send(msg)
			return

		# Get current time - and end time
		currentTime = int(time.time())
		cal         = parsedatetime.Calendar()
		time_struct, parse_status = cal.parse(endtime)
		start       = datetime(*time_struct[:6])
		end         = time.mktime(start.timetuple())

		# Get the time from now to end time
		timeFromNow = end-currentTime

		if timeFromNow < 1:
			# Less than a second - set it to 1 second
			end = currentTime+1
			timeFromNow = 1

		# Get our readable time
		readableTime = ReadableTime.getReadableTimeBetween(int(currentTime), int(end))

		# Add reminder
github wireservice / agate / agate / data_types / date_time.py View on Github external
def __setstate__(self, dict):
        """
        Restore state from the unpickled state values. Set _parser to an instance
        of the parsedatetime Calendar class.
        """
        self.__dict__.update(dict)
        self._parser = parsedatetime.Calendar(version=parsedatetime.VERSION_CONTEXT_STYLE)
github alfredfrancis / ai-chatbot-framework / ikyCore / functions.py View on Github external
def dateFromString(timeString):
    cal = pdt.Calendar()
    now = datetime.now()
    result = str(cal.parseDT(timeString.strip(), now)[0])
    return result
github reswitched / robocop-ng / cogs / common.py View on Github external
def parse_time(self, delta_str):
        cal = parsedatetime.Calendar()
        time_struct, parse_status = cal.parse(delta_str)
        res_timestamp = math.floor(time.mktime(time_struct))
        return res_timestamp
github koldinger / Tardis / Tardis / Client.py View on Github external
else:
        # Else, no name specified, we're auto.  Create a default name.
        name = time.strftime("Backup_%Y-%m-%d_%H:%M:%S")

    if args.purge:
        purgePriority = priority
        if args.purgeprior:
            purgePriority = args.purgeprior
        if keepdays:
            purgeTime = keepdays * 3600 * 24        # seconds in days
        if args.purgedays:
            purgeTime = args.purgedays * 3600 * 24
        if args.purgehours:
            purgeTime = args.purgehours * 3600
        if args.purgetime:
            cal = parsedatetime.Calendar()
            (then, success) = cal.parse(args.purgetime)
            if success:
                purgeTime = time.mktime(then)
            else:
                #logger.error("Could not parse --keep-time argument: %s", args.purgetime)
                raise Exception("Could not parse --keep-time argument: {} ".format(args.purgetime))

    return (name, priority, auto)
github fake-name / ReadableWebProxy / WebMirror / PreProcessors / QidianPreprocess.py View on Github external
def do_release_for_chap(self, book_data, chap_info):


		itemDate, status = parsedatetime.Calendar().parse(chap_info['createTime'])

		if status < 1:
			self.log.warning("Failed to process release date info: '%s'", chap_info['createTime'])
			return

		reldate = time.mktime(itemDate)

		fake_raw_1 = {
			'srcname'   : "Qidian",
			'published' : reldate,
			'linkUrl'   : "https://www.webnovel.com/book/{book_id}/{chap_id}/".format(
				book_id = book_data['bookId'], chap_id = chap_info['id']),
		}


		fake_raw_2 = {