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

Windows settings time #109

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

Conversation

Gijsreyn
Copy link
Contributor

@Gijsreyn Gijsreyn commented Nov 5, 2024


Addresses issue #34 and #100

@Gijsreyn Gijsreyn marked this pull request as ready for review November 5, 2024 06:56
@Gijsreyn
Copy link
Contributor Author

Gijsreyn commented Nov 5, 2024

@ryfu-msft And this one. There is still an issue that I have opened at PSDesiredStateConfiguration.

# Timezone values are taken from the list of timezones (Get-TimeZone -ListAvailable).Id
# TODO: Track issue 125 on PSDesiredStateConfiguration repository to add a ValidateSet for time zones
[DscProperty(Key)]
# [ValidateSet(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be a validate script; Ref your linked issue - PowerShell/PSDesiredStateConfiguration#125 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only thing that I can think of, is create a enum without the spaces, and add another helper function to translate it. Might be a bit overkill, so I'm curious what the PS team is going to mention.

AliasesToExport = '*'

# DSC resources to export from this module
DscResourcesToExport = @('Time')
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're not going to add it in this PR, once this PR merges I would request that you add a follow up issue to track the addition of adding clocks for different timezones under HKEY_CURRENT_USER\Control Panel\TimeDate\AdditionalClocks\1

image

Copy link
Contributor Author

@Gijsreyn Gijsreyn Nov 5, 2024

Choose a reason for hiding this comment

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

I'll put it on #100

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Trenly I have partially started on this one. Do you mind sharing your thoughts on #100 how we are going to set both 1 and 2 in the registry?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would implement it as a single AdditionalClock resource, which has Properties of Ensure, TimeZone, DisplayName.

For Get -

  • Fetch the values in 1
  • Compare against properties
  • If the properties match, set ensure present and return the current state
  • If the properties don't match, fetch the values in 2
  • Compare against properties
  • If the properties match, set ensure present; otherwise, set ensure absent
  • Return the current state

For Test -

  • Run Get
  • Compare Ensure of the current state to Ensure of the desired state
  • Return result of comparison

For Set it's a bit more complicated, I'd imagine you'd first want to determine if either 1 or 2 had a matching DisplayName, if it does, set the values for that clock. If no display names match, check if either timezone matches, if it does, set the values for that clock. If neither are a match, put it in slot 1 if the enable property of the slot is not set. If slot 1 is already enabled, put it in slot 2 if the enable property of the slot is not set. If slot 2 is already enabled, throw an error that the maximum number of additional clocks have been set.


Alternatively, you could just add a parameter for Id and restrict it to being 1 or 2 and have it be mandatory for Set operations but optional for Get and Test. That's honestly probably the better option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the details. One small question, how will users be able to specify both 1 and 2 in a single configuration document?

Copy link
Contributor

Choose a reason for hiding this comment

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

They call the resource twice - once for setting slot one, and a second time for setting slot two

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 lack the knowledge on this part. Either clock 1 or clock 2 can be turned on, or both. Shouldn't the user be able to say something like: AdditionalClock1Settings and AdditionaClock2Settings?

Copy link
Contributor

Choose a reason for hiding this comment

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

No need; They can confugure like:

    - resource: Microsoft.Windows.Setting.Time/AdditionalClock
      directives:
        description: Set clock 1
        allowPrerelease: true
      settings:
        Slot: 1
        DisplayName: UTC
        Timezone: UTC
        Ensure: Present
    - resource: Microsoft.Windows.Setting.Time/AdditionalClock
      directives:
        description: Set clock 2
        allowPrerelease: true
      settings:
        Slot: 2
        DisplayName: Current time in Redmond
        Timezone: Pacific Standard Time
        Ensure: Present

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah cool. I'll pick it up after this is merged!

This comment has been minimized.

#endRegion Functions

#region Enums
enum TimeZoneTable {
Copy link
Contributor

Choose a reason for hiding this comment

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

This enum seems like overkill. I would just let the time zone id be used directly as a string parameter instead of creating this enum.

class Time {
# TODO: Track issue 125 on PSDesiredStateConfiguration repository to add a ValidateSet for time zones
[DscProperty(Key)]
[TimeZoneTable] $TimeZone = ((Get-TimeZone).Id -replace '[\+\s\-\(\)\.]', '')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
[TimeZoneTable] $TimeZone = ((Get-TimeZone).Id -replace '[\+\s\-\(\)\.]', '')
[string] $TimeZoneId

@microsoft-github-policy-service microsoft-github-policy-service bot removed Changes-Requested Changes Requested Needs-Author-Feedback This needs a response from the author. labels Nov 15, 2024

This comment has been minimized.

This comment has been minimized.

@Gijsreyn
Copy link
Contributor Author

I forgot to add the daylight saving option. Should be good to go now.

@Gijsreyn
Copy link
Contributor Author

Gijsreyn commented Dec 2, 2024

@ryfu-msft And the same for this one :)

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.

3 participants