Skip to content

Commit ce0a39d

Browse files
authored
Merge pull request #325 from lipkau/fix/#324-FixedDateFormat
Fixed DateTime format
2 parents 41d4bb3 + b8b4130 commit ce0a39d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

JiraPS/Public/Add-JiraIssueWorklog.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ function Add-JiraIssueWorklog {
7373
Write-Error @errorMessage
7474
}
7575

76+
# Harmonize DateStarted:
77+
# `Get-Date -Date "01.01.2000"` does not return the local timezone
78+
# which is required by the API
79+
$DateStarted = [DateTime]::new($DateStarted.Ticks, 'Local')
80+
7681
$requestBody = @{
7782
'comment' = $Comment
7883
# We need to fix the date with a RegEx replace because the API does not like:

Tests/Functions/Add-JiraIssueWorklog.Unit.Tests.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Describe "Add-JiraIssueWorklog" -Tag 'Unit' {
103103
}
104104

105105
Mock Invoke-JiraMethod -ModuleName JiraPS -ParameterFilter {$Method -eq 'POST' -and $URI -eq "$jiraServer/rest/api/latest/issue/$issueID/worklog"} {
106-
ShowMockInfo 'Invoke-JiraMethod' 'Method', 'Uri'
106+
ShowMockInfo 'Invoke-JiraMethod' 'Method', 'Uri', 'Body'
107107
ConvertFrom-Json $restResponse
108108
}
109109

@@ -136,5 +136,15 @@ Describe "Add-JiraIssueWorklog" -Tag 'Unit' {
136136
Assert-MockCalled -CommandName Get-JiraIssue -ModuleName JiraPS -Exactly -Times 2 -Scope It
137137
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Exactly -Times 1 -Scope It
138138
}
139+
140+
It "formats DateStarted independetly of the input" {
141+
Add-JiraIssueWorklog -Comment 'This is a test worklog entry from Pester.' -Issue $issueKey -TimeSpent "00:10:00" -DateStarted "2018-01-01"
142+
Add-JiraIssueWorklog -Comment 'This is a test worklog entry from Pester.' -Issue $issueKey -TimeSpent "00:10:00" -DateStarted (Get-Date)
143+
Add-JiraIssueWorklog -Comment 'This is a test worklog entry from Pester.' -Issue $issueKey -TimeSpent "00:10:00" -DateStarted (Get-Date -Date "01.01.2000")
144+
145+
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -ParameterFilter {
146+
$Body -match '\"started\":\s*"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}[\+\-]\d{4}"'
147+
} -Exactly -Times 3 -Scope It
148+
}
139149
}
140150
}

0 commit comments

Comments
 (0)