I am attempting to take all of the start dates of my coworkers and calculate a total # of years of experience. However I am getting the following error
Twig\Error\SyntaxError: Unexpected token "punctuation" of value ":" ("end of statement block" expected). in Twig\TokenStream->expect() (line 44
{% if title %}
<h3>{{ title }}</h3>
{% endif %}
{% set total_seconds = 0 %} {# Initialize a variable to store the total seconds #}
{% for row in rows %}
{%
set row_classes = [
default_row_class ? 'views-row',
]
%}
{# Assuming 'row.content' contains a date field named 'field_start_date' #}
{% set date_str = row.content['#view'].style_plugin.getField(row_index, 'field_start_date') %}
{% if date_str %}
{% set today = date('now') %}
{% set date_object = date(date_str) %}
{# Calculate the difference in seconds using Drupal's date formatter service with createAttribute for options #}
{% set options = create_attribute() %}
{% set options = options.setAttribute('granularity', 1) %}
{% set diff_seconds = Drupal::service('date.formatter')->formatDiff(date_object.getTimestamp(), today.getTimestamp(), 'en', options) %}
{% set total_seconds = total_seconds + diff_seconds %} {# Add the calculated seconds to the total #}
<div{{ row.attributes.addClass(row_classes) }}>
{{- row.content -}}
</div>
{% else %}
<div{{ row.attributes.addClass(row_classes) }}>
{{- row.content -}}
</div>
{% endif %}
{% endfor %}
{% if total_seconds > 0 %}
{% set total_years = (total_seconds / (365 * 24 * 60 * 60))|round(2) %} {# Convert seconds to years and round #}
<p>Total combined years since all dates: {{ total_years }}</p> {# Display the final result #}
{% endif %}
commenting out this line {#% set diff_seconds = Drupal::service('date.formatter')->formatDiff(date_object.getTimestamp(), today.getTimestamp(), 'en', options) %#}
removes any error, but doesn’t return the single value that I am expecting.