Skip to content

Commit

Permalink
We're starting to get several functions and operators that directly o…
Browse files Browse the repository at this point in the history
…perate 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.
  • Loading branch information
cbhaley committed Oct 21, 2024
1 parent 8e9b181 commit 0e3f821
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions manual/template_lang.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions src/calibre/utils/formatter_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,21 +1290,23 @@ def evaluate(self, formatter, kwargs, mi, locals, val, format_string):


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 = ''
Expand Down

0 comments on commit 0e3f821

Please sign in to comment.