mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Merge pull request #137 from Icinga/feature/add-conversion-and-compare-unixtime-feature
Feature: Compare current time with DateTime Object
This commit is contained in:
commit
84e6ff32b1
2 changed files with 29 additions and 0 deletions
|
|
@ -14,6 +14,8 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
|
||||||
* [#136](https://github.com/Icinga/icinga-powershell-framework/pull/136) Adds support to ignore empty check packages and return `Ok` instead of `Unknown` if `-IgnoreEmptyPackage` is set on `New-IcingaCheckPackage`
|
* [#136](https://github.com/Icinga/icinga-powershell-framework/pull/136) Adds support to ignore empty check packages and return `Ok` instead of `Unknown` if `-IgnoreEmptyPackage` is set on `New-IcingaCheckPackage`
|
||||||
|
* [#137](https://github.com/Icinga/icinga-powershell-framework/issues/137) Adds Cmdlet to compare a DateTime object with the current DateTime and return the offset as Integer in seconds
|
||||||
|
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
|
|
|
||||||
27
lib/core/tools/Compare-IcingaUnixTimeWithDateTime.psm1
Normal file
27
lib/core/tools/Compare-IcingaUnixTimeWithDateTime.psm1
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Compare-IcingaUnixTimeWithDateTime compares a DateTime-Object with the current DateTime and returns the offset between these values as Integer
|
||||||
|
.DESCRIPTION
|
||||||
|
Compare-IcingaUnixTimeWithDateTime compares a DateTime-Object with the current DateTime and returns the offset between these values as Integer
|
||||||
|
.PARAMETER DateTime
|
||||||
|
DateTime object you want to compare with the Universal Time
|
||||||
|
.INPUTS
|
||||||
|
System.DateTime
|
||||||
|
.OUTPUTS
|
||||||
|
System.Int64
|
||||||
|
#>
|
||||||
|
function Compare-IcingaUnixTimeWithDateTime() {
|
||||||
|
param (
|
||||||
|
[datetime]$DateTime
|
||||||
|
);
|
||||||
|
|
||||||
|
# This is when the computer starts counting time
|
||||||
|
$UnixEpochStart = (New-Object DateTime 1970, 1, 1, 0, 0, 0, ([DateTimeKind]::Utc));
|
||||||
|
# We convert the creation and current time to seconds
|
||||||
|
$CreationTime = [long][System.Math]::Floor((($DateTime.ToUniversalTime() - $UnixEpochStart).Ticks / [timespan]::TicksPerSecond));
|
||||||
|
$CurrentTime = Get-IcingaUnixTime;
|
||||||
|
|
||||||
|
# To find out, from the snapshot creation time to the current time, how many seconds are,
|
||||||
|
# you have to subtract from the (Current Time in s) the (Creation Time in s)
|
||||||
|
return ($CurrentTime - $CreationTime);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue