We're starting to get several functions and operators that directly operate on fields. I decided to use a naming convention where they begin with "field_". This commit changes the existing function format_date_field() to field_format_date(), adding an alias for the original name for compatibility.

This commit is contained in:
Charles Haley 2024-10-21 23:24:55 +01:00
parent 8e9b1812fb
commit 0e3f821cbb
2 changed files with 9 additions and 7 deletions

View File

@ -558,10 +558,10 @@ In `GPM` the functions described in `Single Function Mode` all require an additi
format_date(raw_field('pubdate'), 'yyyy')
* ``format_date_field(field_name, format_string)`` -- format the value in the field ``field_name``, which must be the lookup name of date field, either standard or custom. See ``format_date()`` for the formatting codes. This function is much faster than format_date and should be used when you are formatting the value in a field (column). It can't be used for computed dates or dates in string variables. Examples::
* ``field_format_date(field_name, format_string)`` -- format the value in the field ``field_name``, which must be the lookup name of date field, either standard or custom. See ``format_date()`` for the formatting codes. This function is much faster than format_date and should be used when you are formatting the value in a field (column). It can't be used for computed dates or dates in string variables. Alias: format_date_field. Examples::
format_date_field('pubdate', 'yyyy.MM.dd')
format_date_field('#date_read', 'MMM dd, yyyy')
field_format_date('pubdate', 'yyyy.MM.dd')
field_format_date('#date_read', 'MMM dd, yyyy')
* ``formats_modtimes(date_format_string)`` -- return a comma-separated list of colon-separated items ``FMT:DATE`` representing modification times for the formats of a book. The ``date_format_string`` parameter specifies how the date is to be formatted. See the ``format_date()`` function for details. You can use the ``select`` function to get the modification time for a specific format. Note that format names are always uppercase, as in EPUB.
* ``formats_paths()`` -- return a comma-separated list of colon-separated items ``FMT:PATH`` giving the full path to the formats of a book. You can use the select function to get the path for a specific format. Note that format names are always uppercase, as in EPUB.

View File

@ -1290,21 +1290,23 @@ class BuiltinFormatDate(BuiltinFormatterFunction):
class BuiltinFormatDateField(BuiltinFormatterFunction):
name = 'format_date_field'
name = 'field_format_date'
arg_count = 2
category = 'Formatting values'
__doc__ = doc = _("format_date_field(field_name, format_string) -- format "
__doc__ = doc = _("field_format_date(field_name, format_string) -- format "
"the value in the field 'field_name', which must be the lookup name "
"of date field, either standard or custom. See 'format_date' for "
"the formatting codes. This function is much faster than format_date "
"and should be used when you are formatting the value in a field "
"(column). It can't be used for computed dates or dates in string "
"variables. Example: format_date_field('pubdate', 'yyyy.MM.dd')")
"variables. Example: format_date_field('pubdate', 'yyyy.MM.dd'). "
"Alias: format_date_field")
aliases = ['format_date_field']
def evaluate(self, formatter, kwargs, mi, locals, field, format_string):
try:
if field not in mi.all_field_keys():
return _('Unknown field %s passed to function %s')%(field, 'format_date_field')
return _('Unknown field %s passed to function %s')%(field, 'field_format_date')
val = mi.get(field, None)
if val is None:
s = ''