DateTimeFile

class grill.names.DateTimeFile(name='', sep=' ')[source]

Time based file names respecting iso standard.

Config:

year

Between datetime.MINYEAR and datetime.MAXYEAR inclusive.

month

Between 1 and 12 inclusive.

day

Between 1 and the number of days in the given month of the given year.

hour

In range(24).

minute

In range(60).

second

In range(60).

microsecond

In range(1000000).

Composed Fields:

date

year month day

time

hour minute second microsecond

Note

When getting a new default name, current ISO time at the moment of execution is used.

Example:
>>> tf = DateTimeFile.get_default(suffix='txt')
>>> tf.day
'28'
>>> tf.date
'2019-10-28'
>>> tf.year = 1999
>>> tf
DateTimeFile("1999-10-28 22-29-31-926548.txt")
>>> tf.month = 14  # ISO format validation
Traceback (most recent call last):
    ...
ValueError: month must be in 1..12
>>> tf.datetime
datetime.datetime(1999, 10, 28, 22, 29, 31, 926548)
Parameters:
get_pattern_list()[source]

Fields / properties names (sorted) to be used when building names.

Defaults to [date, time] + keys of this name’s config

Return type:

List[str]

config = mappingproxy({'month': '\\d{1,2}', 'day': '\\d{1,2}', 'hour': '\\d{1,2}', 'minute': '\\d{1,2}', 'second': '\\d{1,2}', 'year': '\\d{1,4}', 'microsecond': '\\d{1,6}'})
property datetime: datetime

Return a datetime.datetime object using this name values.

>>> tf = DateTimeFile("1999-10-28 22-29-31-926548.txt")
>>> tf.datetime
datetime.datetime(1999, 10, 28, 22, 29, 31, 926548)
join = mappingproxy({'date': ('year', 'month', 'day'), 'time': ('hour', 'minute', 'second', 'microsecond')})
property name: str

This object’s solved name.

Raises:

ValueError – If an invalid string is provided when setting the attribute.