Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: ScheduledTask: Allow better handling of multiple time zones #440

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

Borgquite
Copy link
Contributor

@Borgquite Borgquite commented Nov 26, 2024

Pull Request (PR) description

Various fixes for StartTime handling in ScheduledTask:

  • StartTime is now processed on the device, rather than at compile time. This makes it possible to configure start times based on each device's timezone offset, rather than being fixed to the time zone offset active on the device where the Desired State Configuration compilation was run. This may be a breaking change if people are relying on the old behaviour (configuring all devices based on the compiling devices' timezone offset) - but a fixed offset can still be supplied at compile time, and this new flexibility makes it possible to configure (e.g.) many servers to rotate logs at 12:00:00AM, local time, without knowing their timezone offsets.
  • Fixed SynchronizeAcrossTimeZone issue where Test always throws False when a date & time is used where Daylight Savings Time is in operation (ScheduledTask: NOTMATCH when using SynchronizeAcrossTimeZone #374). We were picking up the device’s current timezone offset (Get-Date -Format ‘zzz’) (which if the device uses a timezone that has DST, varies throughout the year) instead of the offset associated with the configuration date/time (which, provided a date is included, is fixed even when DST applies).
  • Changed the default StartTime date from today to 1st January 1980 to prevent configuration flip flopping, and added note to configuration README to advise always supplying a date, and not just a time.
  • Added examples & note to configuration README to supply a timezone offset when using SynchronizeAcrossTimeZone.
  • Allow SynchronizeAcrossTimeZone to be used when adding ScheduleType triggers other than 'Once', 'Daily' and 'Weekly'.
  • Fixed Test-DateStringContainsTimeZone to correctly process DateTime strings with negative timezone offsets (-) as well as UTC timezone offsets using Zulu 'Z' string.

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry to the change log under the Unreleased section of the
    file CHANGELOG.md. Entry should say what was changed and how that
    affects users (if applicable), and reference the issue being resolved
    (if applicable).
  • Resource documentation added/updated in README.md.
  • Resource parameter descriptions added/updated in README.md, schema.mof
    and comment-based help.
  • Comment-based help added/updated.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Community Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Community Testing Guidelines.
  • New/changed code adheres to DSC Community Style Guidelines.

This change is Reviewable

@johlju johlju requested a review from PlagueHO November 26, 2024 16:49
@johlju
Copy link
Member

johlju commented Nov 26, 2024

@PlagueHO if you have time, please review this one. 🙂

@johlju
Copy link
Member

johlju commented Nov 28, 2024

@Borgquite seems the tests fail - guessing you are working on it?

@Borgquite
Copy link
Contributor Author

@johlju Yes - getting there, I'll post when done :)

Copy link

codecov bot commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87%. Comparing base (5965697) to head (1d02de3).

Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #440   +/-   ##
===================================
  Coverage    87%    87%           
===================================
  Files        21     21           
  Lines      2081   2082    +1     
===================================
+ Hits       1819   1820    +1     
  Misses      262    262           
Files with missing lines Coverage Δ
...Resources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 91% <100%> (+<1%) ⬆️

@Borgquite
Copy link
Contributor Author

@PlagueHO @johlju All done, ready for someone to review :)

@PlagueHO
Copy link
Member

Oh cool. Let me get onto this tomorrow night

@Borgquite
Copy link
Contributor Author

@PlagueHO Thanks - let me know how it goes :)

@johlju johlju added the needs review The pull request needs a code review. label Dec 2, 2024
Copy link
Contributor

@dan-hughes dan-hughes left a comment

Choose a reason for hiding this comment

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

:lgtm:

Just the one query on the known issue.

Reviewed 4 of 9 files at r1, 1 of 5 files at r2, 4 of 4 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Borgquite and @PlagueHO)


source/DSCResources/DSC_ScheduledTask/README.md line 15 at r4 (raw file):

When creating a scheduled task with a StartTime, you should always specify both
a date and a time, with the SortableDateTimePattern format (e.g. 1980-01-01T00:00:00).
Not providing a date may result in 'flip flopping' if the remote server enters daylight
savings time. The date and time specified will be set based on the time zone that has been
configured on the device. If you want to synchronize a scheduled task across timezones,
use the SynchronizeAcrossTimeZone parameter, and specify the timezone offset that is needed
(e.g. 1980-01-01T00:00:00-08:00).

Should this potentially be enforced to ensure the user does not run into this (fixed in another issue maybe)?

Copy link
Contributor Author

@Borgquite Borgquite left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dan-hughes and @PlagueHO)


source/DSCResources/DSC_ScheduledTask/README.md line 15 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Should this potentially be enforced to ensure the user does not run into this via another issue maybe?

An interesting thought. The difference between a Scheduled Task with SynchronizeAcrossTimeZone enabled, and one without, under the hood appears to be whether it is stored in UTC with the 'Z' offset, or without an offset at all.

I could see a situation where someone might not want to configure the offset (which, as of this change, should result in a task created using the system's configured timezone) but still wants SATZ enabled - it would work. It would be unusual, but perhaps someone might then want to export the scheduled task to XML and import it to another server, and therefore not defining an offset and SATZ could be desirable, even if very unusual.

In general I feel that we should only prevent something happening when it will cause an error - not just when it's perhaps 'not recommended'. The current behavior allows what is possible via the user interface (configuring a scheduled task and presuming the local timezone, even with SATZ enabled). I'd probably prefer to leave as-is (advice, not enforced) just in case there are edge cases like the one above where not defining the timezone but still enabling SATZ could be useful.

@dan-hughes
Copy link
Contributor

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dan-hughes and @PlagueHO)

source/DSCResources/DSC_ScheduledTask/README.md line 15 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…
An interesting thought. The difference between a Scheduled Task with SynchronizeAcrossTimeZone enabled, and one without, under the hood appears to be whether it is stored in UTC with the 'Z' offset, or without an offset at all.

I could see a situation where someone might not want to configure the offset (which, as of this change, should result in a task created using the system's configured timezone) but still wants SATZ enabled - it would work. It would be unusual, but perhaps someone might then want to export the scheduled task to XML and import it to another server, and therefore not defining an offset and SATZ could be desirable, even if very unusual.

In general I feel that we should only prevent something happening when it will cause an error - not just when it's perhaps 'not recommended'. The current behavior allows what is possible via the user interface (configuring a scheduled task and presuming the local timezone, even with SATZ enabled). I'd probably prefer to leave as-is (advice, not enforced) just in case there are edge cases like the one above where not defining the timezone but still enabling SATZ could be useful.

Makes sense. If someone does want to export and they've configured using DSC, it's not really a typical use case.

@PlagueHO, looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review The pull request needs a code review.
Projects
None yet
4 participants