Skip to content

Adjust teamviewer plugin to account for daylight savings time in timestamps#1614

Merged
Miauwkeru merged 13 commits intomainfrom
teamviewer-timezone-parsing
Mar 19, 2026
Merged

Adjust teamviewer plugin to account for daylight savings time in timestamps#1614
Miauwkeru merged 13 commits intomainfrom
teamviewer-timezone-parsing

Conversation

@Miauwkeru
Copy link
Contributor

  • Use the target timezone in the teamviewer plugin if the utcoffsets match
  • Rewrite parse_start to account for only (UTC) inside the string

closes #1488

@Miauwkeru Miauwkeru requested a review from twiggler March 9, 2026 14:32
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.09%. Comparing base (4ba8f14) to head (c442096).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1614      +/-   ##
==========================================
+ Coverage   81.06%   81.09%   +0.03%     
==========================================
  Files         402      402              
  Lines       35244    35264      +20     
==========================================
+ Hits        28571    28599      +28     
+ Misses       6673     6665       -8     
Flag Coverage Δ
unittests 81.09% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 9, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing teamviewer-timezone-parsing (c442096) with main (4ba8f14)

Open in CodSpeed

self.target.log.debug("", exc_info=e)
timestamp = 0

if timestamp:
Copy link
Contributor

@twiggler twiggler Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we have the target timezone self.target.datetime.tzinfo,

what if we renormalize every timestamp, instead of detecting deltas:

naive_dt = datetime.strptime(f"{date} {time}", "%Y/%m/%d %H:%M:%S.%f")
timestamp = naive_dt.replace(tzinfo=target_tz)

if prev_timestamp and prev_timestamp > timestamp:
     timestamp = timestamp.replace(fold=1)
 
prev_timestamp = timestamp

Would that not also help with "spring forward" events?

In other words, why not rely on the target_tz calendar rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that the fold was used for this. I did notice when working on it that the fold doesn't get passed to flow.record. I made this PR for it fox-it/flow.record#217

@Miauwkeru
Copy link
Contributor Author

I decided to ignore the gap that happens when daylight savings time occurs, as that timestamp should not get generated normally

Determine whether the timezone found by parsing `Start:` is the same
timezone as that of the target. This automatically adjust the timestamp
when dst time ends or starts.

There is a grey area where it cannot determine whether a timestamp is in
dst time or not, so when it is observed that the previous timestamp was
less than the current one, it adjust the timezone for those entries
(UTC+XXXX)
@Miauwkeru Miauwkeru force-pushed the teamviewer-timezone-parsing branch from 59c3895 to 2d708e1 Compare March 12, 2026 09:07
@Miauwkeru Miauwkeru requested a review from twiggler March 12, 2026 09:41
Comment on lines 195 to 198
except Exception as e:
self.target.log.warning("Unable to parse timestamp %r in file %s", line, logfile)
self.target.log.debug("", exc_info=e)
timestamp = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this cause a timestamp of 0 to be yielded? Not sure if that behaviour is expected.

Suggested change
except Exception as e:
self.target.log.warning("Unable to parse timestamp %r in file %s", line, logfile)
self.target.log.debug("", exc_info=e)
timestamp = 0
except Exception as e:
self.target.log.warning("Unable to parse timestamp %r in file %s", line, logfile)
self.target.log.debug("", exc_info=e)
continue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also confused about that, as it would return 1 January 1970, but didn't touch it as it is how it worked before.
This does mean we won't be able to get a record if we couldn't parse the timestamp. Tho, it is still available in the logging.

With this patch, other logic can also be updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having a log line without a timestamp is preferred over ignoring the log line altogether, as it could hold forensic value.

Copy link
Contributor Author

@Miauwkeru Miauwkeru Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only times I have seen this code path occurring is specifically with the following entries after Start: which occurs when the teamviewer service gets started:

Start:              2026/03/05 13:33:56.539 (UTC+5:30)
Version:            15.74.6 (64-bit)
Version short hash: e34788d05e8
ID:                 0
Loglevel:           Critical
License:            0
IC:                 -2056635597
CPU:                Intel64 Family 6 Model 141 Stepping 1, GenuineIntel
CPU extensions:     k0
OS:                 Win_10.0.26100_W (64-bit)
IP:                 127.0.0.1
MID:                0x525400fad56f_1da8405dc678cec_983722041
MIDv:               0
Proxy-Settings:     Type=1 IP= User=
IE:                 11.1.26100.0
AppPath:            C:\Program Files\TeamViewer\TeamViewer_Service.exe
UserAccount:        SYSTEM
Server-Environment: Global

All following entries have a timestamp until another Start: gets is found.
It could be a good compromise to use timestamp=start_time here instead, as those entries belong to start_time

In the worst case, the entries won't have any timestamp then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could store the last timestamp we encountered and use that one instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we already store the previous timestamp for overlap detection that should be fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JSCU-CNI I changed it to use the previous timestamp. Note that this path is only reached when the timestamp contains a number that is invalid for a timestamp. For example:

2025/10/26 02:50:90.300

If the time regex itself doesn't match, for example if the timestamp contained a letter instead of a number, it already gets ignored

Co-authored-by: Stefan de Reuver <9864602+Horofic@users.noreply.github.com>
@Miauwkeru Miauwkeru force-pushed the teamviewer-timezone-parsing branch from 867cb2c to 451c426 Compare March 17, 2026 10:02
@Miauwkeru Miauwkeru requested a review from Horofic March 17, 2026 10:04
Horofic
Horofic previously approved these changes Mar 17, 2026
@Miauwkeru Miauwkeru dismissed twiggler’s stale review March 17, 2026 10:19

changes have been implemented

@Miauwkeru Miauwkeru requested a review from JSCU-CNI March 17, 2026 13:14
…ion occurred during parsing

The only case it gets in this exception is when `Start:` gets parsed and
the next lines contain some system information.

Technically those records have the same time as the start_date

In the worst case scenario the `start_date` would be None if there is an
error or the line couldn't get parsed.
Need to be invalid times that exceed normal datetime behaviour, because
if they are not numbers they are already ignored due to the regex not
matching
@Miauwkeru Miauwkeru requested a review from Horofic March 19, 2026 09:45
Copy link
Member

@Horofic Horofic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the len() calls in the check_compatible function? Other that ack.

@Miauwkeru Miauwkeru requested a review from Horofic March 19, 2026 12:36
@Miauwkeru Miauwkeru merged commit 945ad90 into main Mar 19, 2026
37 of 45 checks passed
@Miauwkeru Miauwkeru deleted the teamviewer-timezone-parsing branch March 19, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TeamViewer plugin timezone parsing issue

4 participants