query stringlengths 9 60 | language stringclasses 1
value | code stringlengths 105 25.7k | url stringlengths 91 217 |
|---|---|---|---|
string to date | python | def date_to_string(date):
"""Transform a date or datetime object into a string and return it.
Examples:
>>> date_to_string(datetime.datetime(2012, 1, 3, 12, 23, 34, tzinfo=UTC))
'2012-01-03T12:23:34+00:00'
>>> date_to_string(datetime.datetime(2012, 1, 3, 12, 23, 34))
'2012-01-03T12:23:34'
>... | https://github.com/mozilla/socorrolib/blob/4ec08c6a4ee2c8a69150268afdd324f5f22b90c8/socorrolib/lib/datetimeutil.py#L94-L120 |
string to date | python | def toString(self):
""" Returns date as string. """
slist = self.toList()
sign = '' if slist[0] == '+' else '-'
string = '/'.join(['%02d' % v for v in slist[1:]])
return sign + string | https://github.com/flatangle/flatlib/blob/44e05b2991a296c678adbc17a1d51b6a21bc867c/flatlib/datetime.py#L93-L98 |
string to date | python | def date(self, pattern='%Y-%m-%d', end_datetime=None):
"""
Get a date string between January 1, 1970 and now
:param pattern format
:example '2008-11-27'
"""
return self.date_time(end_datetime=end_datetime).strftime(pattern) | https://github.com/joke2k/faker/blob/965824b61132e52d92d1a6ce470396dbbe01c96c/faker/providers/date_time/__init__.py#L1436-L1442 |
string to date | python | def getDate():
"""Returns a formatted string with the current date."""
_ltime = _time.localtime(_time.time())
date_str = _time.strftime('%Y-%m-%dT%H:%M:%S',_ltime)
return date_str | https://github.com/spacetelescope/stsci.tools/blob/9a022503ad24ca54ce83331482dfa3ff6de9f403/lib/stsci/tools/fileutil.py#L162-L168 |
string to date | python | def date_string_to_date(p_date):
"""
Given a date in YYYY-MM-DD, returns a Python date object. Throws a
ValueError if the date is invalid.
"""
result = None
if p_date:
parsed_date = re.match(r'(\d{4})-(\d{2})-(\d{2})', p_date)
if parsed_date:
result = date(
... | https://github.com/bram85/topydo/blob/b59fcfca5361869a6b78d4c9808c7c6cd0a18b58/topydo/lib/Utils.py#L28-L46 |
string to date | python | def stringToDateTime(s, tzinfo=None):
"""
Returns datetime.datetime object.
"""
try:
year = int(s[0:4])
month = int(s[4:6])
day = int(s[6:8])
hour = int(s[9:11])
minute = int(s[11:13])
second = int(s[13:15])
if len(s) > 15:
if s[15] == ... | https://github.com/eventable/vobject/blob/498555a553155ea9b26aace93332ae79365ecb31/vobject/icalendar.py#L1726-L1745 |
string to date | python | def stringToDateTime(s, tzinfo=None):
"""Returns datetime.datetime object."""
try:
year = int(s[0:4])
month = int(s[4:6])
day = int(s[6:8])
hour = int(s[9:11])
minute = int(s[11:13])
second = int(s[13:15])
if len(s) > 15:
if s[15] == 'Z':
... | https://github.com/tBaxter/python-card-me/blob/ffebc7fed44f83983b7438e57263dcda67207664/card_me/icalendar.py#L1620-L1635 |
string to date | python | def string_to_date(input):
"""Convert string to date object.
:param input: the date string to parse
:type input: str
:returns: the parsed datetime object
:rtype: datetime.datetime
"""
# try date formats --mmdd, --mm-dd, yyyymmdd, yyyy-mm-dd and datetime
# formats yyyymmddThhmmss, yyyy-m... | https://github.com/scheibler/khard/blob/0f69430c2680f1ff5f073a977a3c5b753b96cc17/khard/helpers.py#L81-L107 |
string to date | python | def date(value):
"""
Returns a date literal if value is likely coercible to a date
Parameters
----------
value : date value as string
Returns
--------
result : TimeScalar
"""
if isinstance(value, str):
value = to_date(value)
return literal(value, type=dt.date) | https://github.com/ibis-project/ibis/blob/1e39a5fd9ef088b45c155e8a5f541767ee8ef2e7/ibis/expr/api.py#L277-L291 |
string to date | python | def to_string(self, style=None, utcoffset=None):
"""Return a |str| object representing the actual date in
accordance with the given style and the eventually given
UTC offset (in minutes).
Without any input arguments, the actual |Date.style| is used
to return a date string in you... | https://github.com/hydpy-dev/hydpy/blob/1bc6a82cf30786521d86b36e27900c6717d3348d/hydpy/core/timetools.py#L686-L734 |
string to date | python | def get_date(date):
"""
Get the date from a value that could be a date object or a string.
:param date: The date object or string.
:returns: The date object.
"""
if type(date) is str:
return datetime.strptime(date, '%Y-%m-%d').date()
else:
return date | https://github.com/Ex-Mente/auxi.0/blob/2dcdae74154f136f8ca58289fe5b20772f215046/auxi/core/helpers.py#L23-L34 |
string to date | python | def parseDateText(self, dateString):
"""
Parse long-form date strings::
'May 31st, 2006'
'Jan 1st'
'July 2006'
@type dateString: string
@param dateString: text to convert to a datetime
@rtype: struct_time
@return: calcu... | https://github.com/vilmibm/done/blob/7e5b60d2900ceddefa49de352a19b794199b51a8/parsedatetime/parsedatetime.py#L389-L440 |
string to date | python | def parseDate(self, dateString):
"""
Parse short-form date strings::
'05/28/2006' or '04.21'
@type dateString: string
@param dateString: text to convert to a C{datetime}
@rtype: struct_time
@return: calculated C{struct_time} value of dateString
... | https://github.com/vilmibm/done/blob/7e5b60d2900ceddefa49de352a19b794199b51a8/parsedatetime/parsedatetime.py#L312-L386 |
string to date | python | def datetime_string(day, month, year, hour, minute):
"""Build a date string using the provided day, month, year numbers.
Automatically adds a leading zero to ``day`` and ``month`` if they only have
one digit.
Args:
day (int): Day number.
month(int): Month number.
year(int): Yea... | https://github.com/rmed/pyemtmad/blob/c21c42d0c7b50035dfed29540d7e64ab67833728/pyemtmad/util.py#L87-L107 |
string to date | python | def _date_by_len(self, string):
"""
Parses a date from a string based on its length
:param string:
A unicode string to parse
:return:
A datetime.datetime object or a unicode string
"""
strlen = len(string)
year_num = int(string[0:2])
... | https://github.com/wbond/asn1crypto/blob/ecda20176f55d37021cbca1f6da9083a8e491197/asn1crypto/core.py#L4692-L4717 |
string to date | python | def to_datetime_string(self) -> str:
""" Returns a human-readable string representation with iso date and time
Example: 2018-12-06 12:32:56
"""
date_display = self.to_iso_date_string()
time_display = self.to_long_time_string()
return f"{date_display} {time_display}" | https://github.com/MisterY/pydatum/blob/4b39f43040e31a95bcf219603b6429078a9ba3c2/pydatum/datum.py#L196-L202 |
string to date | python | def string_to_date(value):
"""
Return a Python date that corresponds to the specified string
representation.
@param value: string representation of a date.
@return: an instance ``datetime.datetime`` represented by the string.
"""
if isinstance(value, datetime.date):
return value
... | https://github.com/dcaune/perseus-lib-python-common/blob/ba48fe0fd9bb4a75b53e7d10c41ada36a72d4496/majormode/perseus/utils/cast.py#L172-L184 |
string to date | python | def string_to_data_time(d):
'''
simple parse date string, such as:
2016-5-27 21:22:20
2016-05-27 21:22:2
2016/05/27 21:22:2
2016-05-27
2016/5/27
21:22:2
'''
if d:
d = d.replace('/', '-')
if ' ' in d:
_datetime = d.split(' ')
if len(_datet... | https://github.com/hustcc/timeago/blob/819fc6efefeccea2a39e6c1cb2f20b5d2cc9f613/src/timeago/parser.py#L74-L100 |
string to date | python | def from_str(date):
"""
Given a date in the format: Jan,21st.2015
will return a datetime of it.
"""
month = date[:3][0] + date[:3][-2:].lower()
if month not in NAMED_MONTHS:
raise CanNotFormatError('Month not recognized')
date = date.replace('... | https://github.com/shinux/PyTime/blob/f2b9f877507e2a1dddf5dd255fdff243a5dbed48/pytime/filter.py#L259-L276 |
string to date | python | def convert_date(d, custom_date_string=None, fallback=None):
"""
for whatever reason, sometimes WP XML has unintelligible
datetime strings for pubDate.
In this case default to custom_date_string or today
Use fallback in case a secondary date string is available.
Incident... | https://github.com/thelabnyc/wagtail_blog/blob/7e092c02d10ec427c9a2c4b5dcbe910d88c628cf/blog/wp_xml_parser.py#L132-L153 |
string to date | python | def parseDateText(self, dateString, sourceTime=None):
"""
Parse long-form date strings::
'May 31st, 2006'
'Jan 1st'
'July 2006'
@type dateString: string
@param dateString: text to convert to a datetime
@type sourceTime: struct_time
... | https://github.com/bear/parsedatetime/blob/830775dc5e36395622b41f12317f5e10c303d3a2/parsedatetime/__init__.py#L483-L550 |
string to date | python | def _parse_date_string(date_str):
"""
Get a datetime.date object from a string date representation.
The FCS standard includes an optional keyword parameter $DATE in
which the acquistion date is stored. In FCS 2.0, the date is saved
as 'dd-mmm-yy', whereas in FCS 3.0 and 3.1 the ... | https://github.com/taborlab/FlowCal/blob/031a7af82acb1d46879a8e384a1a00f27f0bdc7a/FlowCal/io.py#L1827-L1877 |
string to date | python | def parse_date(string_date):
"""
Parse the given date as one of the following
* Git internal format: timestamp offset
* RFC 2822: Thu, 07 Apr 2005 22:13:13 +0200.
* ISO 8601 2005-04-07T22:13:13
The T can be a space as well
:return: Tuple(int(timestamp_UTC), int(offset))... | https://github.com/gitpython-developers/GitPython/blob/1f66e25c25cde2423917ee18c4704fff83b837d1/git/objects/util.py#L131-L202 |
string to date | python | def str_to_datetime(ts):
"""Format a string to a datetime object.
This functions supports several date formats like YYYY-MM-DD, MM-DD-YYYY
and YY-MM-DD. When the given data is None or an empty string, the function
returns None.
:param ts: string to convert
:returns: a datetime object
:ra... | https://github.com/chaoss/grimoirelab-sortinghat/blob/391cd37a75fea26311dc6908bc1c953c540a8e04/sortinghat/utils.py#L87-L107 |
string to date | python | def stringToDate(fmt="%Y-%m-%d"):
"""returns a function to convert a string to a datetime.date instance
using the formatting string fmt as in time.strftime"""
import time
import datetime
def conv_func(s):
return datetime.date(*time.strptime(s,fmt)[:3])
return conv_func | https://github.com/andreasjansson/head-in-the-clouds/blob/32c1d00d01036834dc94368e7f38b0afd3f7a82f/headintheclouds/dependencies/PyDbLite/PyDbLiteConv.py#L3-L10 |
string to date | python | def _to_date(t):
'''
Internal function that tries whatever to convert ``t`` into a
:class:`datetime.date` object.
>>> _to_date('2013-12-11')
datetime.date(2013, 12, 11)
>>> _to_date('Wed, 11 Dec 2013')
datetime.date(2013, 12, 11)
>>> _to_date('Wed, 11 Dec 13')
datetime.date(2013, 12... | https://github.com/tehmaze/natural/blob/d7a1fc9de712f9bcf68884a80826a7977df356fb/natural/date.py#L97-L129 |
string to date | python | def parse_date(date_string):
"""
Parse the given string as datetime object. This parser supports in almost any string formats.
For relative times, like `10min ago`, this parser computes the actual time relative to current UTC time. This
allows time to always be in UTC if an explicit time zone is not pr... | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/lib/utils/time.py#L91-L117 |
string to date | python | def to_dates(param):
"""
This function takes a date string in various formats
and converts it to a normalized and validated date range. A list
with two elements is returned, lower and upper date boundary.
Valid inputs are, for example:
2012 => Jan 1 20012 - Dec 31 2012 (whole year)... | https://github.com/marians/py-daterangestr/blob/fa5dd78c8fea5f91a85bf732af8a0bc307641134/daterangestr.py#L33-L65 |
string to date | python | def parse_date(self, value):
"""
A lazy method to parse anything to date.
If input data type is:
- string: parse date from it
- integer: use from ordinal
- datetime: use date part
- date: just return it
"""
if isinstance(value, sixmini.string_typ... | https://github.com/MacHu-GWU/rolex-project/blob/a1111b410ed04b4b6eddd81df110fa2dacfa6537/rolex/parse.py#L226-L248 |
string to date | python | def convertDate(date):
"""Convert DATE string into a decimal year."""
d, t = date.split('T')
return decimal_date(d, timeobs=t) | https://github.com/spacetelescope/stsci.tools/blob/9a022503ad24ca54ce83331482dfa3ff6de9f403/lib/stsci/tools/fileutil.py#L171-L175 |
string to date | python | def dateparser(fmt, strict=True):
"""Return a function to parse strings as :class:`datetime.date` objects
using a given format. E.g.::
>>> from petl import dateparser
>>> isodate = dateparser('%Y-%m-%d')
>>> isodate('2002-12-25')
datetime.date(2002, 12, 25)
>>> try:
... | https://github.com/petl-developers/petl/blob/1d33ca055f7e04e0d28a772041c9fd30c8d415d6/petl/util/parsers.py#L39-L67 |
string to date | python | def str2date(self, datestr):
"""Try parse date from string. If None template matching this datestr,
raise Error.
:param datestr: a string represent a date
:type datestr: str
:return: a datetime.date object
Usage::
>>> from weatherl... | https://github.com/MacHu-GWU/angora-project/blob/689a60da51cd88680ddbe26e28dbe81e6b01d275/angora/timelib/timewrapper.py#L190-L225 |
string to date | python | def parse_date(string, formation=None):
"""
string to date stamp
:param string: date string
:param formation: format string
:return: datetime.date
"""
if formation:
_stamp = datetime.datetime.strptime(string, formation).date()
return _stamp... | https://github.com/shinux/PyTime/blob/f2b9f877507e2a1dddf5dd255fdff243a5dbed48/pytime/filter.py#L178-L220 |
string to date | python | def _datetime_to_date(arg):
"""
convert datetime/str to date
:param arg:
:return:
"""
_arg = parse(arg)
if isinstance(_arg, datetime.datetime):
_arg = _arg.date()
return _arg | https://github.com/shinux/PyTime/blob/f2b9f877507e2a1dddf5dd255fdff243a5dbed48/pytime/pytime.py#L182-L191 |
string to date | python | def to_date(dt, tzinfo=None, format=None):
"""
Convert a datetime to date with tzinfo
"""
d = to_datetime(dt, tzinfo, format)
if not d:
return d
return date(d.year, d.month, d.day) | https://github.com/limodou/uliweb/blob/34472f25e4bc0b954a35346672f94e84ef18b076/uliweb/utils/date.py#L161-L168 |
string to date | python | def convert_time_string(date_str):
""" Change a date string from the format 2018-08-15T23:55:17 into a datetime object """
dt, _, _ = date_str.partition(".")
dt = datetime.strptime(dt, "%Y-%m-%dT%H:%M:%S")
return dt | https://github.com/jmbhughes/suvi-trainer/blob/3d89894a4a037286221974c7eb5634d229b4f5d4/suvitrainer/fileio.py#L29-L33 |
string to date | python | def str2date(self, date_str):
"""
Parse date from string.
If there's no template matches your string, Please go
https://github.com/MacHu-GWU/rolex-project/issues
submit your datetime string. I 'll update templates ASAP.
This method is faster than :meth:`dateutil.parser.... | https://github.com/MacHu-GWU/rolex-project/blob/a1111b410ed04b4b6eddd81df110fa2dacfa6537/rolex/parse.py#L129-L168 |
string to date | python | def year(date):
""" Returns the year.
:param date:
The string date with this format %m/%d/%Y
:type date:
String
:returns:
int
:example:
>>> year('05/1/2015')
2015
"""
try:
fmt = '%m/%d/%Y'
return datetime.strptime(date, fmt).timetupl... | https://github.com/developmentseed/landsat-util/blob/92dc81771ddaa64a8a9124a89a6516b52485374b/landsat/utils.py#L213-L232 |
string to date | python | def parse_date(date_str):
"""
Check if date_str is in a recognised format and return an ISO
yyyy-mm-dd format version if so. Raise DateFormatError if not.
Recognised formats are:
* RFC 7231 (e.g. Mon, 09 Sep 2011 23:36:00 GMT)
* RFC 850 (e.g. Sunday, 06-Nov-94 08:49:37 G... | https://github.com/sam-washington/requests-aws4auth/blob/1201e470c6d5847b7fe42e937a55755e1895e72c/requests_aws4auth/aws4auth.py#L397-L452 |
string to date | python | def _convert_date_time_string(dt_string):
'''
convert string to date time object
'''
dt_string = dt_string.split('.')[0]
dt_obj = datetime.strptime(dt_string, '%Y%m%d%H%M%S')
return dt_obj.strftime('%Y-%m-%d %H:%M:%S') | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/win_system.py#L70-L76 |
string to date | python | def format_date(cls, timestamp):
"""
Creates a string representing the date information provided by the
given `timestamp` object.
"""
if not timestamp:
raise DateTimeFormatterException('timestamp must a valid string {}'.format(timestamp))
return timestamp.str... | https://github.com/polyaxon/hestia/blob/382ed139cff8bf35c987cfc30a31b72c0d6b808e/hestia/date_formatter.py#L30-L38 |
string to date | python | def get_date(cls, name):
""" Checks a string for a possible date formatted into the name. It assumes dates do not have other
numbers at the front or head of the date. Currently only supports dates in 1900 and 2000.
Heavily relies on datetime for error checking to see
if dat... | https://github.com/AndresMWeber/Nomenclate/blob/e6d6fc28beac042bad588e56fbe77531d2de6b6f/nomenclate/core/nameparser.py#L185-L235 |
string to date | python | def get_date_yyyymmdd(yyyymmdd):
"""Return datetime.date given string."""
return date(int(yyyymmdd[:4]), int(yyyymmdd[4:6], base=10), int(yyyymmdd[6:], base=10)) | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/annoreader_base.py#L139-L141 |
string to date | python | def convert_date(date):
"""Convert string to datetime object."""
date = convert_month(date, shorten=False)
clean_string = convert_string(date)
return datetime.strptime(clean_string, DATE_FMT.replace('-','')) | https://github.com/sharibarboza/py_zap/blob/ce90853efcad66d3e28b8f1ac910f275349d016c/py_zap/utils.py#L91-L95 |
string to date | python | def str_to_date(self):
"""
Returns the date attribute as a date object.
:returns: Date of the status if it exists.
:rtype: date or NoneType
"""
if hasattr(self, 'date'):
return date(*list(map(int, self.date.split('-'))))
else:
return None | https://github.com/rodynnz/xccdf/blob/1b9dc2f06b5cce8db2a54c5f95a8f6bcf5cb6981/src/xccdf/models/status.py#L69-L80 |
string to date | python | def to_iso_datetime(dt):
'''
Format a date or datetime into an ISO-8601 datetime string.
Time is set to 00:00:00 for dates.
Support dates before 1900.
'''
if dt:
date_str = to_iso_date(dt)
time_str = '{dt.hour:02d}:{dt.minute:02d}:{dt.second:02d}'.format(
dt=dt) if ... | https://github.com/opendatateam/udata/blob/f016585af94b0ff6bd73738c700324adc8ba7f8f/udata/utils.py#L167-L179 |
string to date | python | def parse_date(self, item, field_name, source_name):
"""
Converts the date in the format: Thu 03.
As only the day is provided, tries to find the best match
based on the current date, considering that dates are on
the past.
"""
# Get the current date
now =... | https://github.com/ricobl/django-importer/blob/6967adfa7a286be7aaf59d3f33c6637270bd9df6/sample_project/tasks/importers.py#L64-L88 |
string to date | python | def parse_date(value):
"""Parse one of the following date formats into a datetime object:
.. sourcecode:: text
Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
Sun Nov 6 08:49:37 1994 ; ANSI C's asctime... | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L780-L809 |
string to date | python | def _to_date_in_588(date_str):
"""
Convert date in the format ala 03.02.2017 to 3.2.2017.
Viz #100 for details.
"""
try:
date_tokens = (int(x) for x in date_str.split("."))
except ValueError:
return date_str
return ".".join(str(x) for x in date_tokens) | https://github.com/WebarchivCZ/WA-KAT/blob/16d064a3a775dc1d2713debda7847ded52dd2a06/src/wa_kat/rest_api/to_output.py#L225-L236 |
string to date | python | def str2date(self, datestr):
"""Parse date from string. If no template matches this string,
raise Error. Please go
https://github.com/MacHu-GWU/rolex-project/issues
submit your date string. I 'll update templates asap.
This method is faster than :meth:`dateutil.parser.parse`.
... | https://github.com/MacHu-GWU/pymongo_mate-project/blob/be53170c2db54cb705b9e548d32ef26c773ff7f3/pymongo_mate/pkg/pandas_mate/pkg/rolex/__init__.py#L69-L109 |
string to date | python | def match_date(date):
"""Check if a string is a valid date
Args:
date(str)
Returns:
bool
"""
date_pattern = re.compile("^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])")
if re.match(date_pattern, date):
return True
return False | https://github.com/Clinical-Genomics/scout/blob/90a551e2e1653a319e654c2405c2866f93d0ebb9/scout/utils/date.py#L4-L17 |
string to date | python | def parse_dates(d, default='today'):
""" Parses one or more dates from d """
if default == 'today':
default = datetime.datetime.today()
if d is None:
return default
elif isinstance(d, _parsed_date_types):
return d
elif is_number(d):
# Treat as milliseconds since 1... | https://github.com/consbio/parserutils/blob/f13f80db99ed43479336b116e38512e3566e4623/parserutils/dates.py#L9-L40 |
string to date | python | def convertToDate(fmt="%Y-%m-%d"):
"""
Helper to create a parse action for converting parsed date string to Python datetime.date
Params -
- fmt - format to be passed to datetime.strptime (default= ``"%Y-%m-%d"``)
Example::
date_expr = pyparsing_common.iso8601_date... | https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/vendor/pyparsing.py#L6136-L6158 |
string to date | python | def calculate_date_strings(self, mode, numDays):
"""Returns a tuple of start (in YYYY-MM-DD format) and end date
strings (in YYYY-MM-DD HH:MM:SS format for an inclusive day)."""
yesterday = date.today() - timedelta(days=1)
endday = datetime(yesterday.year, yesterday.month, yesterday.... | https://github.com/mozilla/treeherder/blob/cc47bdec872e5c668d0f01df89517390a164cda3/treeherder/intermittents_commenter/commenter.py#L172-L184 |
string to date | python | def to_date(ts: float) -> datetime.date:
"""Convert timestamp to date.
>>> to_date(978393600.0)
datetime.date(2001, 1, 2)
"""
return datetime.datetime.fromtimestamp(
ts, tz=datetime.timezone.utc).date() | https://github.com/darkfeline/animanager/blob/55d92e4cbdc12aac8ebe302420d2cff3fa9fa148/animanager/datets.py#L34-L41 |
string to date | python | def parseDate(self, dateString, sourceTime=None):
"""
Parse short-form date strings::
'05/28/2006' or '04.21'
@type dateString: string
@param dateString: text to convert to a C{datetime}
@type sourceTime: struct_time
@param sourceTime: C{struct_tim... | https://github.com/bear/parsedatetime/blob/830775dc5e36395622b41f12317f5e10c303d3a2/parsedatetime/__init__.py#L394-L481 |
string to date | python | def parsehttpdate(string_):
"""
Parses an HTTP date into a datetime object.
>>> parsehttpdate('Thu, 01 Jan 1970 01:01:01 GMT')
datetime.datetime(1970, 1, 1, 1, 1, 1)
"""
try:
t = time.strptime(string_, "%a, %d %b %Y %H:%M:%S %Z")
except ValueError:
return None
re... | https://github.com/talkincode/toughlib/blob/1c2f7dde3a7f101248f1b5f5d428cc85466995cf/toughlib/btforms/net.py#L126-L137 |
string to date | python | def parse_http_date(date: str) -> int:
"""
解析http时间到 timestamp
"""
try:
return int(
datetime.strptime(
date,
ISO_DATE_FORMAT,
).timestamp(),
)
except ValueError:
return 0 | https://github.com/zeromake/aiko/blob/53b246fa88652466a9e38ac3d1a99a6198195b0f/aiko/utils.py#L67-L79 |
string to date | python | def format_date(
self,
date: Union[int, float, datetime.datetime],
gmt_offset: int = 0,
relative: bool = True,
shorter: bool = False,
full_format: bool = False,
) -> str:
"""Formats the given date (which should be GMT).
By default, we return a relativ... | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/locale.py#L323-L421 |
string to date | python | def _parse_date(string: str) -> datetime.date:
"""Parse an ISO format date (YYYY-mm-dd).
>>> _parse_date('1990-01-02')
datetime.date(1990, 1, 2)
"""
return datetime.datetime.strptime(string, '%Y-%m-%d').date() | https://github.com/darkfeline/animanager/blob/55d92e4cbdc12aac8ebe302420d2cff3fa9fa148/animanager/migrations.py#L184-L190 |
string to date | python | def string_to_datetime(date):
"""Return a datetime.datetime instance with tzinfo.
I.e. a timezone aware datetime instance.
Acceptable formats for input are:
* 2012-01-10T12:13:14
* 2012-01-10T12:13:14.98765
* 2012-01-10T12:13:14.98765+03:00
* 2012-01-10T12:13:14.98765Z
... | https://github.com/mozilla/socorrolib/blob/4ec08c6a4ee2c8a69150268afdd324f5f22b90c8/socorrolib/lib/datetimeutil.py#L46-L91 |
string to date | python | def parseDate(dateString, strict=True):
"""
Return a datetime object, by parsing a string date/time
With strict=False, dateString may be None or '', otherwise it must be a
parseable string
"""
if (not strict) and (not dateString):
return None
if not isinstance(dateString, basestrin... | https://github.com/corydodt/Codado/blob/487d51ec6132c05aa88e2f128012c95ccbf6928e/codado/py.py#L200-L213 |
string to date | python | def formatted_date(self, fmt: str = '', **kwargs) -> str:
"""Generate random date as string.
:param fmt: The format of date, if None then use standard
accepted in the current locale.
:param kwargs: Keyword arguments for :meth:`~Datetime.date()`
:return: Formatted date.
... | https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/date.py#L146-L159 |
string to date | python | def is_date(v) -> (bool, date):
"""
Boolean function for checking if v is a date
Args:
v:
Returns: bool
"""
if isinstance(v, date):
return True, v
try:
reg = r'^([0-9]{4})(?:-(0[1-9]|1[0-2])(?:-(0[1-9]|[1-2][0-9]|3[0-1])(?:T' ... | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/knowledge_graph_schema.py#L171-L194 |
string to date | python | def match_date(self, value, strict=False):
"""if value is a date"""
value = stringify(value)
try:
parse(value)
except Exception:
self.shout('Value %r is not a valid date', strict, value) | https://github.com/alephdata/memorious/blob/b4033c5064447ed5f696f9c2bbbc6c12062d2fa4/memorious/logic/check.py#L43-L49 |
string to date | python | def str_to_datetime(ts):
"""Format a string to a datetime object.
This functions supports several date formats like YYYY-MM-DD,
MM-DD-YYYY, YY-MM-DD, YYYY-MM-DD HH:mm:SS +HH:MM, among others.
When the timezone is not provided, UTC+0 will be set as default
(using `dateutil.tz.tzutc` object).
:p... | https://github.com/chaoss/grimoirelab-toolkit/blob/30f36e89f3070f1a7b9973ea3c8a31f4b792ee2b/grimoirelab_toolkit/datetime.py#L97-L148 |
string to date | python | def string_to_datetime(self, obj):
"""
Decode a datetime string to a datetime object
"""
if isinstance(obj, six.string_types) and len(obj) == 19:
try:
return datetime.strptime(obj, "%Y-%m-%dT%H:%M:%S")
except ValueError:
pass
... | https://github.com/aparo/pyes/blob/712eb6095961755067b2b5baa262008ade6584b3/pyes/es.py#L127-L146 |
string to date | python | def dateFormat(when):
"""
Format the date when, e.g. Friday 14th of April 2011
"""
retval = ""
if when is not None:
dow = dateformat.format(when, "l")
dom = dateformat.format(when, "jS")
month = dateformat.format(when, "F")
if when.year != dt.date.today().year:
... | https://github.com/linuxsoftware/ls.joyous/blob/316283140ca5171a68ad3170a5964fdc89be0b56/ls/joyous/utils/telltime.py#L103-L118 |
string to date | python | def strpdate(string, format):
"""Parse the date string according to the format in `format`. Returns a
:class:`date` object. Internally, :meth:`datetime.strptime` is used to
parse the string and thus conversion specifiers for time fields (e.g. `%H`)
may be provided; these will be parsed but ignored.
... | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/_vendor/boltons/timeutils.py#L253-L277 |
string to date | python | def deserialize_date(string):
"""
Deserializes string to date.
:param string: str.
:type string: str
:return: date.
:rtype: date
"""
try:
from dateutil.parser import parse
return parse(string).date()
except ImportError:
return string | https://github.com/nmdp-bioinformatics/SeqAnn/blob/5ce91559b0a4fbe4fb7758e034eb258202632463/seqann/util.py#L257-L270 |
string to date | python | def parse_date(self, value):
"""A lazy method to parse anything to date.
If input data type is:
- string: parse date from it
- integer: use from ordinal
- datetime: use date part
- date: just return it
"""
if value is None:
raise Exception("U... | https://github.com/MacHu-GWU/pymongo_mate-project/blob/be53170c2db54cb705b9e548d32ef26c773ff7f3/pymongo_mate/pkg/pandas_mate/pkg/rolex/__init__.py#L158-L179 |
string to date | python | def format_date(self, value, format_):
"""
Format the date using Babel
"""
date_ = make_date(value)
return dates.format_date(date_, format_, locale=self.lang) | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/i18n/_formatter.py#L80-L85 |
string to date | python | def string_to_timestamp(timestring):
"""
Accepts a str, returns an int timestamp.
"""
ts = None
# Uses an extended version of Go's duration string.
try:
delta = durationpy.from_str(timestring);
past = datetime.datetime.utcnow() - delta
ts = calendar.timegm(past.timetupl... | https://github.com/Miserlou/Zappa/blob/3ccf7490a8d8b8fa74a61ee39bf44234f3567739/zappa/utilities.py#L91-L111 |
string to date | python | def _date_by_len(self, string):
"""
Parses a date from a string based on its length
:param string:
A unicode string to parse
:return:
A datetime.datetime object, asn1crypto.util.extended_datetime object or
a unicode string
"""
strlen... | https://github.com/wbond/asn1crypto/blob/ecda20176f55d37021cbca1f6da9083a8e491197/asn1crypto/core.py#L4750-L4790 |
string to date | python | def date(self, col: str, **kwargs):
"""
Convert a column to date type
:param col: column name
:type col: str
:param \*\*kwargs: keyword arguments for ``pd.to_datetime``
:type \*\*kwargs: optional
:example: ``ds.date("mycol")``
"""
try:
... | https://github.com/synw/dataswim/blob/4a4a53f80daa7cd8e8409d76a19ce07296269da2/dataswim/data/clean.py#L279-L293 |
string to date | python | def StringToUTCTime(time_string):
"""
Turns a DateTime string into UTC time.
:param time_string: Must be the format "MM/dd/yy hh:mm:ss"
:return: an integer representing the UTC int format
"""
szTime = c_char_p(time_string.encode('utf-8'))
res = dna_dll.StringToUTCTime(szTime)
r... | https://github.com/drericstrong/pyedna/blob/b8f8f52def4f26bb4f3a993ce3400769518385f6/pyedna/ezdna.py#L744-L753 |
string to date | python | def parse_date(date_string, ignoretz=True):
"""Parse a string as a date. If the string fails to parse, `None` will be returned instead
>>> parse_date('2017-08-15T18:24:31')
datetime.datetime(2017, 8, 15, 18, 24, 31)
Args:
date_string (`str`): Date in string format to parse
ignoretz (`b... | https://github.com/RiotGames/cloud-inquisitor/blob/181dc2566ca59fc855f695b7fcc2c3b934e6ee9f/backend/cloud_inquisitor/utils.py#L440-L456 |
string to date | python | def _date2int(date):
"""
Returns an integer representation of a date.
:param str|datetime.date date: The date.
:rtype: int
"""
if isinstance(date, str):
if date.endswith(' 00:00:00') or date.endswith('T00:00:00'):
# Ignore time suffix.
... | https://github.com/SetBased/py-etlt/blob/1c5b8ea60293c14f54d7845a9fe5c595021f66f2/etlt/helper/Type2Helper.py#L89-L110 |
string to date | python | def parse_date(date_str):
"""Parse elastic datetime string."""
if not date_str:
return None
try:
date = ciso8601.parse_datetime(date_str)
if not date:
date = arrow.get(date_str).datetime
except TypeError:
date = arrow.get(date_str[0]).datetime
return date | https://github.com/petrjasek/eve-elastic/blob/f146f31b348d22ac5559cf78717b3bb02efcb2d7/eve_elastic/elastic.py#L25-L36 |
string to date | python | def set_date(date):
'''
Set the current month, day, and year
:param str date: The date to set. Valid date formats are:
- %m:%d:%y
- %m:%d:%Y
- %m/%d/%y
- %m/%d/%Y
:return: True if successful, False if not
:rtype: bool
:raises: SaltInvocationError on Invalid Da... | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/mac_timezone.py#L78-L105 |
string to date | python | def datetime_to_str(date_time=None, str_format='%Y-%m-%d_%H:%M:%S.fff'):
"""
:param date_time: datetime of the date to convert to string
:param str_format: str of the format to return the string in
:return: str of the timestamp
"""
date_time = date_time or cst_now()
if DEFAULT_TIMEZONE_A... | https://github.com/SeabornGames/Timestamp/blob/2b6902ddc2a009d6f3cb4dd0f6882bf4345f3871/seaborn_timestamp/timestamp.py#L97-L111 |
string to date | python | def _str_to_datetime(self, str_value):
"""Parses a `YYYY-MM-DD` string into a datetime object."""
try:
ldt = [int(f) for f in str_value.split('-')]
dt = datetime.datetime(*ldt)
except (ValueError, TypeError):
return None
return dt | https://github.com/jpscaletti/solution/blob/eabafd8e695bbb0209242e002dbcc05ffb327f43/solution/fields/splitted_datetime.py#L83-L90 |
string to date | python | def date(self, field=None, val=None):
"""
Like datetime, but truncated to be a date only
"""
return self.datetime(field=field, val=val).date() | https://github.com/BetterWorks/django-anonymizer/blob/2d25bb6e8b5e4230c58031c4b6d10cc536669b3e/anonymizer/base.py#L135-L139 |
string to date | python | def parse_json_date(value):
"""
Parses an ISO8601 formatted datetime from a string value
"""
if not value:
return None
return datetime.datetime.strptime(value, JSON_DATETIME_FORMAT).replace(tzinfo=pytz.UTC) | https://github.com/rapidpro/expressions/blob/b03d91ec58fc328960bce90ecb5fa49dcf467627/python/temba_expressions/utils.py#L50-L57 |
string to date | python | def _parse_date_perforce(aDateString):
"""parse a date in yyyy/mm/dd hh:mm:ss TTT format"""
# Fri, 2006/09/15 08:19:53 EDT
_my_date_pattern = re.compile( \
r'(\w{,3}), (\d{,4})/(\d{,2})/(\d{2}) (\d{,2}):(\d{2}):(\d{2}) (\w{,3})')
m = _my_date_pattern.search(aDateString)
if m is None:
... | https://github.com/jmoiron/speedparser/blob/e7e8d79daf73b35c9259695ad1e379476e1dfc77/speedparser/feedparsercompat.py#L557-L571 |
string to date | python | def date_to_timestamp(date):
"""
date to unix timestamp in milliseconds
"""
date_tuple = date.timetuple()
timestamp = calendar.timegm(date_tuple) * 1000
return timestamp | https://github.com/telminov/sw-django-utils/blob/43b8491c87a5dd8fce145834c00198f4de14ceb9/djutils/date_utils.py#L39-L45 |
string to date | python | def FromTimeString(
cls, time_string, dayfirst=False, gmt_as_timezone=True,
timezone=pytz.UTC):
"""Converts a string containing a date and time value into a timestamp.
Args:
time_string: String that contains a date and time value.
dayfirst: An optional boolean argument. If set to true t... | https://github.com/log2timeline/plaso/blob/9c564698d2da3ffbe23607a3c54c0582ea18a6cc/plaso/lib/timelib.py#L268-L314 |
string to date | python | def inc_date(date_obj, num, date_fmt):
"""Increment the date by a certain number and return date object.
as the specific string format.
"""
return (date_obj + timedelta(days=num)).strftime(date_fmt) | https://github.com/sharibarboza/py_zap/blob/ce90853efcad66d3e28b8f1ac910f275349d016c/py_zap/utils.py#L107-L111 |
string to date | python | def parse_date(table_data):
"""
Static method that parses a given table data element with `Url.DATE_STRPTIME_FORMAT` and creates a `date` object from td's text contnet.
:param lxml.HtmlElement table_data: table_data tag to parse
:return: date object from td's text date
:rtype: d... | https://github.com/syndbg/demonoid-api/blob/518aa389ac91b5243b92fc19923103f31041a61e/demonoid/parser.py#L78-L91 |
string to date | python | def strptime(cls, date_string, fmt):
"""
This is opposite of the :py:meth:`khayyam.JalaliDate.strftime`,
and used to parse date strings into date object.
`ValueError` is raised if the date_string and format can’t be
parsed by time.strptime() or if it returns a value which isn’t ... | https://github.com/pylover/khayyam/blob/7e3a30bb941f8dc8bad8bf9d3be2336fed04bb57/khayyam/jalali_date.py#L155-L173 |
string to date | python | def __deserialize_date(self, string):
"""
Deserializes string to date.
:param string: str.
:return: date.
"""
try:
from dateutil.parser import parse
return parse(string).date()
except ImportError:
return string
except V... | https://github.com/kubernetes-client/python/blob/5e512ff564c244c50cab780d821542ed56aa965a/kubernetes/client/api_client.py#L573-L589 |
string to date | python | def parse_date(string, force_datetime=False):
""" Takes a Xero formatted date, e.g. /Date(1426849200000+1300)/"""
matches = DATE.match(string)
if not matches:
return None
values = dict([
(
k,
v if v[0] in '+-' else int(v)
) for k,v in matches.groupdict().... | https://github.com/freakboy3742/pyxero/blob/5566f17fa06ed1f2fb9426c112951a72276b0f9a/xero/utils.py#L64-L97 |
string to date | python | def timestring_to_datetime(timestring):
"""
Convert an ISO formated date and time string to a datetime object.
:param str timestring: String with date and time in ISO format.
:rtype: datetime
:return: datetime object
"""
with warnings.catch_warnings():
warnings.filterwarnings("ignor... | https://github.com/topic2k/pygcgen/blob/c41701815df2c8c3a57fd5f7b8babe702127c8a1/pygcgen/generator.py#L26-L38 |
string to date | python | def _get_expiration_date(cert):
'''
Returns a datetime.datetime object
'''
cert_obj = _read_cert(cert)
if cert_obj is None:
raise CommandExecutionError(
'Failed to read cert from {0}, see log for details'.format(cert)
)
return datetime.strptime(
salt.utils.s... | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/tls.py#L612-L626 |
string to date | python | def get_date(date, date_format = None):
"""Return a datetime object if there is a valid date
Raise exception if date is not valid
Return todays date if no date where added
Args:
date(str)
date_format(str)
Returns:
date_obj(datetime.datetime)
... | https://github.com/Clinical-Genomics/scout/blob/90a551e2e1653a319e654c2405c2866f93d0ebb9/scout/utils/date.py#L19-L50 |
string to date | python | def format_date_string(self, date_tuple):
"""
Receives a date_tuple object, and outputs a string
for placement in the article content.
"""
months = ['', 'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November',... | https://github.com/SavinaRoja/OpenAccess_EPUB/blob/6b77ba30b7394fd003920e7a7957bca963a90656/src/openaccess_epub/publisher/__init__.py#L539-L556 |
string to date | python | def date_between(self, start_date='-30y', end_date='today'):
"""
Get a Date object based on a random date between two given dates.
Accepts date strings that can be recognized by strtotime().
:param start_date Defaults to 30 years ago
:param end_date Defaults to "today"
:... | https://github.com/joke2k/faker/blob/965824b61132e52d92d1a6ce470396dbbe01c96c/faker/providers/date_time/__init__.py#L1574-L1587 |
string to date | python | def n_day(date_string):
"""
date_string string in format "(number|a) day(s) ago"
"""
today = datetime.date.today()
match = re.match(r'(\d{1,3}|a) days? ago', date_string)
groups = match.groups()
if groups:
decrement = groups[0]
if decrement... | https://github.com/askedrelic/journal/blob/848b8ec67ed124ec112926211ebeccbc8d11f2b0/journal/parse.py#L27-L39 |
string to date | python | def parse_date(datestring):
"""Attepmts to parse an ISO8601 formatted ``datestring``.
Returns a ``datetime.datetime`` object.
"""
datestring = str(datestring).strip()
if not datestring[0].isdigit():
raise ParseError()
if 'W' in datestring.upper():
try:
datestring =... | https://github.com/slickqa/python-client/blob/1d36b4977cd4140d7d24917cab2b3f82b60739c2/slickqa/micromodels/packages/PySO8601/datetimestamps.py#L91-L120 |
string to date | python | def from_string(date_str):
"""
construction from the following string patterns
'%Y-%m-%d'
'%d.%m.%Y'
'%m/%d/%Y'
'%Y%m%d'
:param str date_str:
:return BusinessDate:
"""
if date_str.count('-'):
str_format = '%Y-%m-%d'
eli... | https://github.com/pbrisk/businessdate/blob/79a0c5a4e557cbacca82a430403b18413404a9bc/businessdate/businessdate.py#L205-L235 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.