Coverage Report

Created: 2025-11-09 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dovecot/src/lib/utc-offset.c
Line
Count
Source
1
/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
2
3
#include "lib.h"
4
#include "utc-offset.h"
5
6
#include <sys/time.h>
7
8
int utc_offset(struct tm *tm, time_t t ATTR_UNUSED)
9
0
{
10
0
#ifdef HAVE_TM_GMTOFF
11
0
  return (int) (tm->tm_gmtoff/60);
12
#else
13
  struct tm ltm, gtm;
14
  int offset;
15
16
  /* gmtime() overwrites tm, so we need to copy it elsewhere */
17
  ltm = *tm;
18
  tm = gmtime(&t);
19
  gtm = *tm;
20
21
  /* max offset of 24 hours */
22
  if ((ltm.tm_yday < gtm.tm_yday && ltm.tm_year == gtm.tm_year) ||
23
      ltm.tm_year < gtm.tm_year)
24
    offset = -24 * 60;
25
  else if ((ltm.tm_yday > gtm.tm_yday && ltm.tm_year == gtm.tm_year) ||
26
     ltm.tm_year > gtm.tm_year)
27
    offset = 24 * 60;
28
  else
29
    offset = 0;
30
31
  offset += (ltm.tm_hour - gtm.tm_hour) * 60;
32
  offset += (ltm.tm_min - gtm.tm_min);
33
34
  /* restore overwritten tm */
35
  *tm = ltm;
36
  return offset;
37
#endif
38
0
}