function UnixTimeStampToDateT ime long unixTimeStamp UnixEpoch New-Obj

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function UnixTimeStampToDateTime([long]$unixTimeStamp)
{
$UnixEpoch = New-Object DateTime @(1970, 1, 1, 0, 0, 0, 0, "Utc")
return $UnixEpoch.AddMilliseconds($unixTimeStamp).ToLocalTime()
}
$me = "pkudinov"
$pass = "PASSWORD"
Invoke-RestMethod `
-Uri "http://youtrack.crossmarket.across.lan/rest/user/login" `
-Body @{login="acrosssys\$me"; password=$pass} `
-Method Post `
-SessionVariable sess `
-ErrorAction Stop | Out-Null
if(-not $?) {
throw "Could not login."
}
$ticketsResponse = Invoke-RestMethod `
-Uri "http://youtrack.crossmarket.across.lan/rest/issue?filter=for+%23me+updated%3A+Today" `
-Method Get `
-WebSession $sess
$ids = $tickets.issueCompacts.issue.id
$allWorkItems = $ids `
| % { Invoke-RestMethod -Uri "http://youtrack.crossmarket.across.lan/rest/issue/$_/timetracking/workitem" -Method Get -WebSession $sess } `
| %{$_.workitems.workitem}
$myWorkItems = @( $allWorkItems |? {$_.author.login -eq $me -and (UnixTimeStampToDateTime $_.date).Date -eq [DateTime]::Today} )
$totalDuration = ($myWorkItems.duration | measure -Sum).Sum
[timespan]::FromMinutes( $totalDuration ).ToString()