Skip to content

Commit

Permalink
Fix starttime and endtime timezone issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavis332 committed Jan 31, 2022
1 parent fa2fb36 commit 9a64fc3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
6 changes: 3 additions & 3 deletions CIF3.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
RootModule = 'CIF3.psm1'

# Version number of this module.
ModuleVersion = '0.9.8'
ModuleVersion = '0.9.9'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand All @@ -24,7 +24,7 @@
CompanyName = 'REN-ISAC'

# Copyright statement for this module
Copyright = '(c) 2020 REN-ISAC. All rights reserved.'
Copyright = '(c) 2022 REN-ISAC. All rights reserved.'

# Description of the functionality provided by this module
Description = 'PowerShell module wrapper for the Collective Intelligence Framework (CIF) v3 API'
Expand Down Expand Up @@ -105,7 +105,7 @@
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = 'Fixes encrypt/decrypt function causing failures on non-Windows OSes.'
ReleaseNotes = 'Fixes potential timezone issue with StartTime and EndTime params.'

} # End of PSData hashtable

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 REN-ISAC
Copyright (c) 2022 REN-ISAC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
25 changes: 25 additions & 0 deletions Private/ConvertTo-ReportTimeUTC.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function ConvertTo-ReportTimeUTC {
# Helper function that takes two DateTime objects (StartTime and EndTime) and
# standardizes to UTC before returning a comma-separated string of the values
param(
[Parameter(Mandatory = $true)]
[datetime]$StartTime,

[Parameter(Mandatory = $true)]
[datetime]$EndTime
)

begin { }

process {
# try to set datetime object to a string the API will like
$StrStart = $StartTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$StrEnd = $EndTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$ReportTime = "$StrStart,$StrEnd"

Write-Verbose "Formatting time boundaries. ReportTime set to $ReportTime"
Write-Output $ReportTime
}

end { }
}
5 changes: 1 addition & 4 deletions Public/Get-CIF3Feed.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ function Get-CIF3Feed {
}

if ($PSBoundParameters.ContainsKey('StartTime')) {
# try to set datetime object to a string the API will like
$StrStart = $StartTime.ToString("yyyy-MM-ddT00:00:00Z") # have to set start time HH:mm:ss to 00:00:00 or CIF doesn't like it
$StrEnd = $EndTime.ToString("yyyy-MM-ddT23:59:59Z") # have to set end time HH:mm:ss to 23:59:59 or CIF isn't happy
$ReportTime = "$StrStart,$StrEnd"
$ReportTime = ConvertTo-ReportTimeUTC -StartTime $StartTime -EndTime $EndTime
$Body.Add('reporttime', $ReportTime)
}

Expand Down
5 changes: 1 addition & 4 deletions Public/Get-CIF3Indicator.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ function Get-CIF3Indicator {
}

if ($PSBoundParameters.ContainsKey('StartTime')) {
# try to set datetime object to a string the API will like
$StrStart = $StartTime.ToString("yyyy-MM-ddT00:00:00Z") # have to set start time HH:mm:ss to 00:00:00 or CIF doesn't like it
$StrEnd = $EndTime.ToString("yyyy-MM-ddT23:59:59Z") # have to set end time HH:mm:ss to 23:59:59 or CIF isn't happy
$ReportTime = "$StrStart,$StrEnd"
$ReportTime = ConvertTo-ReportTimeUTC -StartTime $StartTime -EndTime $EndTime
$Body.Add('reporttime', $ReportTime)
}

Expand Down
2 changes: 1 addition & 1 deletion Public/Tokens/New-CIF3Token.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function New-CIF3Token {
'Acl' { $Body.Add('acl', $Acl) }
'Revoked' { $Body.Add('revoked', $Revoked) }
'Expires' { # try to set datetime object to a string the API will like
$StrExpires = $Expires.ToString("yyyy-MM-ddTHH:mm:ssZ")
$StrExpires = $Expires.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$Body.Add('expires', $StrExpires)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Public/Tokens/Set-CIF3TokenGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function Set-CIF3TokenGroup {
'Admin' { $Body.Add('admin', $Admin) }
'Revoked' { $Body.Add('revoked', $Revoked) }
'Expires' { # try to set datetime object to a string the API will like
$StrExpires = $Expires.ToString("yyyy-MM-ddTHH:mm:ssZ")
$StrExpires = $Expires.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$Body.Add('expires', $StrExpires)
}
}
Expand All @@ -83,7 +83,7 @@ function Set-CIF3TokenGroup {

process {

Write-Verbose 'Token removal on CIF API'
Write-Verbose 'Token update on CIF API'

$Params = @{
Body = $Body
Expand Down

0 comments on commit 9a64fc3

Please sign in to comment.