.. meta::
   :description: Set up Znuny working hours and calendars: default working hours, holidays, calendars 1 to 9 with their own time zone, and how queues and SLAs use them for escalations and pending times.
   :keywords: znuny working hours, calendar, timeworkinghours, timevacationdays, holidays, escalation calendar, queue calendar, sla calendar, pending time, timependingskipunavailabledays

.. _PageNavigation admin_systemconfiguration_workinghours_index:

Working Hours and Calendars
###########################

Working hours decide when escalation times count. A ticket with a first response time of two hours that arrives on Friday evening does not escalate on Saturday morning if nobody works on the weekend. The clock stops outside working hours and on holidays, and starts again on the next working day.

Working hours and holidays are kept in calendars in the System Configuration. These are not the appointment calendars agents see in the :ref:`calendar overview <PageNavigation agentinterface_appointments_overview>`.

Znuny has a default calendar and nine more, numbered 1 to 9. A queue or a service level agreement (SLA) that has no calendar selected uses the default calendar.

The Default Calendar
********************

The default calendar is in the System Configuration under **Core > Time**.

.. figure:: images/workinghours_navigation.png
   :alt: Image workinghours_navigation

   Core > Time with the calendars 1 to 9

``TimeWorkingHours``
   The hours that count as working time for each day of the week. Out of the box, these are Monday to Friday from 8:00 to 21:00. Saturday and Sunday have no working hours.

``TimeVacationDays``
   Holidays that fall on the same date every year. The defaults are New Year's Day, International Workers' Day (1 May), Christmas Eve, the first and second Christmas Day and New Year's Eve. Replace them with the holidays of your country.

``TimeVacationDaysOneTime``
   Holidays for one year only, such as Easter or a company event. The default contains a placeholder entry called *test* on 1 January 2004, which you can delete.

``TimePendingSkipUnavailableDays``
   See :ref:`PageNavigation admin_systemconfiguration_workinghours_pending`.

``CalendarWeekDayStart``
   The first day of the week in the date picker.

The default calendar has no time zone of its own. It uses ``ZnunyTimeZone``, see :ref:`Pagenavigation admin_systemconfiguration_timezones_index`.

Calendars 1 to 9
****************

Each of the calendars 1 to 9 has its own group under **Core > Time > Calendar1** to **Calendar9** with the same settings as the default calendar, plus a name and a time zone:

- ``TimeZone::Calendar1Name``: the name shown when you select the calendar in a queue or SLA. The default is *Calendar Name 1*.
- ``TimeZone::Calendar1``: the time zone the working hours are read in. This setting is disabled by default, and the calendar then uses ``ZnunyTimeZone``.
- ``TimeWorkingHours::Calendar1``, ``TimeVacationDays::Calendar1``, ``TimeVacationDaysOneTime::Calendar1``, ``TimePendingSkipUnavailableDays::Calendar1`` and ``CalendarWeekDayStart::Calendar1``, which work like the settings of the default calendar.

The default values are the same as in the default calendar.

.. note::

   A calendar is only used while its name is set. If you clear ``TimeZone::Calendar1Name``, tickets in queues with calendar 1 fall back to the default calendar.

Example: A Second Team in Another Country
*****************************************

Your service desk works from Berlin, and a second team in New York takes the tickets of the queue *Service Desk US*. The New York team works Monday to Friday from 9:00 to 17:00 local time and has US public holidays. Without its own calendar, its escalations would be counted in Berlin working hours.

Set up calendar 1 for the New York team:

1. Open Admin > System Configuration and navigate to **Core > Time > Calendar1**.
2. Set ``TimeZone::Calendar1Name`` to *New York*.
3. Enable ``TimeZone::Calendar1`` and select *America/New_York*.
4. In ``TimeWorkingHours::Calendar1``, select the hours 9 to 16 for Monday to Friday. Each selected hour counts as a full working hour, so 9 to 16 means 9:00 to 17:00.
5. Replace the entries in ``TimeVacationDays::Calendar1`` with the US holidays that fall on a fixed date, such as Independence Day (4 July).
6. Add the holidays that move every year, such as Thanksgiving, to ``TimeVacationDaysOneTime::Calendar1``.
7. Deploy the changes.

.. figure:: images/workinghours_calendar1.png
   :alt: Image workinghours_calendar1

   Calendar 1 set up for a team in New York

Then assign the calendar to the team's queue:

1. Open Admin > :ref:`Queues <PageNavigation admin_queues_index>` and select *Service Desk US*.
2. In **Calendar**, select *Calendar 1 - New York*.
3. Save.

.. figure:: images/workinghours_queue_calendar.png
   :alt: Image workinghours_queue_calendar

   Selecting the calendar in a queue

If you use services and SLAs, also select the calendar in the SLAs the New York team works on (Admin > Service Level Agreements > **Calendar**). The next section explains why.

Escalation Time Behavior
************************

Escalation times only count working time in the ticket's calendar. With calendar 1 from the example, a ticket that arrives in *Service Desk US* on Friday at 16:30 New York time with a first response time of one hour escalates on Monday at 9:30 New York time. Agents still see that time in their own time zone.

Which calendar a ticket uses depends on where its escalation times come from (see :ref:`PageNavigation concepts_escalation_index`):

- With services active (``Ticket::Service``) and an SLA assigned, the SLA's times and calendar apply. An SLA without a calendar uses the default calendar, even when the queue has one.
- Without an SLA, the queue's times and calendar apply.

So select the team's calendar in its queue and in every SLA its tickets can have.

.. _PageNavigation admin_systemconfiguration_workinghours_pending:

Effects on Pending States
*************************

When an agent sets a pending state, the date is pre-filled with the current time plus ``Ticket::Frontend::PendingDiffTime`` (one day by default). On a Friday that is a Saturday, when nobody is there to pick up the reminder.

.. versionadded:: 7.5.1

   Enable ``TimePendingSkipUnavailableDays`` to move the pre-filled date forward to the next working day when it falls on a holiday or a day without working hours. For tickets in a calendar 1 to 9, use ``TimePendingSkipUnavailableDays::Calendar1`` to ``::Calendar9``. All are disabled by default.

On an existing ticket, the SLA calendar is used when an SLA is assigned, otherwise the queue calendar, otherwise the default calendar. This applies to the pending screen and to replying, forwarding and moving a ticket. The new phone and email ticket screens always use the default calendar.

Only the pre-filled date changes. Agents can still pick any date. See also :ref:`PageNavigation ticketviews_agentticketreminder`.

The date picker is not affected by these settings. It always highlights holidays and days without working hours in the ticket's calendar, and all days stay selectable.
