Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
please critique of my 'function Get-FirstMondayOfMonth' code
Post Body

[edit -
as u/anynonus pointed out, i failed to test this code. it glitches when the 1st day of the month is either sunday or monday. time for some more testing ... [grin]

edit 2 -
fixed it with a switch to handle sunday/monday as 1st of month.
seems to work correctly now ...

1..12 | ForEach-Object {Get-FirstMondayOfMonth -MonthNumber $_}

]

howdy y'all,

needed a way to find the 1st "some day of month" and decided that it was easier to grab the 1st monday and use that to find the 1st whatever. thus the following code ...

function Get-FirstMondayOfMonth
    {
    <#
    comment based help goes here
    #>

    [CmdletBinding ()]
    Param (
        [Parameter(
            Position = 0
            )]
            [ValidateRange (1,12)]
            [int]
            $MonthNumber = (Get-Date).Month
        )

    if ($MonthNumber)
        {
        $Day_1 = Get-Date -Month $MonthNumber -Day 1
        }
        else
        {
        $Day_1 = Get-Date -Day 1
        }

    switch ($Day_1.DayOfWeek.value__)
        {
        0 {
            $Offset = 1
            break
            }
        1 {
            $Offset = 0
            break
            }
        default {
            # the "  1" is to handle the "off-by-one" array index difference
            $Offset = 7 - $Day_1.Date.DayOfWeek.value__   1
            }

        }

    $Day_1.Date.AddDays($Offset)

    }

other than the lack of CBH [grin], is there anything that i otta change?

take care,
lee

Author
Account Strength
100%
Account Age
11 years
Verified Email
Yes
Verified Flair
No
Total Karma
27,226
Link Karma
672
Comment Karma
25,727
Profile updated: 3 days ago
Posts updated: 8 months ago
[grin]

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago