-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunix.ps1
More file actions
103 lines (98 loc) · 3.49 KB
/
unix.ps1
File metadata and controls
103 lines (98 loc) · 3.49 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Param(
[Parameter(Mandatory=$true,position=0)]
[string]$operation,
[Parameter(Mandatory=$false,position=1)]
[DateTime]$date,
[string]$mode
)
[DateTime]$nowRaw = Get-Date
[int64]$now = ([int64](Get-Date -UFormat %s))
[int64]$unix = 0
# use these values for 'unix discord -d yesterday -m r' or something like that
# example inputs:
# 'unix discord -d in5hr', 'unix discord -d in2d', 'unix discord -d yesterday -m shortdate'
# fallback disc timestamp mode = relative
[int64]$oneHour = 3600
[int64]$oneDay = 86400
[int64]$oneWeek = 604800
[int64]$oneMonth = 2629743
[int64]$oneYear = 31556926
function Set-Current{
Set-Clipboard -Value $now
Write-Host "Written unix time $now to clipboard. ($nowRaw)"
}
function Set-Stamp($timeIn){
switch($mode){
{($_ -eq "r") -or ($_ -eq "relative")} { return "<t:$timeIn`:R>" }
{($_ -eq "lt") -or ($_ -eq "longtime")} { return "<t:$timeIn`:T>" }
{($_ -eq "st") -or ($_ -eq "shorttime")} { return "<t:$timeIn`:t>" }
{($_ -eq "ld") -or ($_ -eq "longdate")} { return "<t:$timeIn`:D>" }
{($_ -eq "sd") -or ($_ -eq "shortdate")} { return "<t:$timeIn`:d>" }
{($_ -eq "sf") -or ($_ -eq "shortfull")} { return "<t:$timeIn`:f>" }
{($_ -eq "lf") -or ($_ -eq "longfull")} { return "<t:$timeIn`:F>" }
Default{
$script:mode = "default"
return "<t:$timeIn>"
}
}
}
switch($operation){
"convert"{
Write-Host "time to convert: $date"
Get-Date -UnixTimeSeconds $date
}
"get"{
if ($null -eq $date){
Set-Current
}
else{
Set-Clipboard -Value (Get-Date -Date $date -UFormat %s)
Write-Host "Written unix time $date to clipboard. ($date)"
}
}
#FIXME: weird format and usage
"discord"{
$timeToStamp = Get-Date -UnixTimeSeconds $date
if ($timeToStamp -ne 0){
Write-Host "Writing discord timestamp for unix time '$timeToStamp' to clipboard:`n" (Get-Date -UnixTimeSeconds $timeToStamp)
$discordStamp = Set-Stamp $timeToStamp
Set-Clipboard -Value $discordStamp
Write-host "Written $mode timestamp with: $discordStamp"
}
elseIf($date -ne ''){
switch($date){
"now"{
$unix = $now
}
"today"{
$unix = $now - ($now % $oneday) - (2 * $oneHour)
}
"midnight"{
$unix = $now - ($now % $oneday) - (2 * $oneHour) + $oneDay
}
"tomorrow"{
$unix = $now + $oneday
}
"yesterday"{
$unix = $now - $oneday
}
# regex recognize date & time{
#
# }
Default{
throw "Could not find date '$date'."
}
}
Write-Host "Writing discord timestamp for '$date' to clipboard:" (Get-Date -UnixTimeSeconds $unix)
Set-Stamp $unix
Set-Clipboard -Value $discordStamp
Write-host "Written $mode timestamp with: $discordStamp"
}
else{
Write-Host "Writing discord timestamp for current time to clipboard:" (Get-Date -UnixTimeSeconds $now)
Set-Stamp $now
Set-Clipboard -Value $discordStamp
Write-host "Written $mode timestamp with: $discordStamp"
}
}
}