-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegEx_Dates.ahk
161 lines (152 loc) · 2.76 KB
/
RegEx_Dates.ahk
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;
; AutoHotkey updating to be used with relative dates ("T", "T+7", etc.)
;
; ***Requires Hotstrings.ahk #included in same launch***
;
;
;include the following in your launch file:
;handle calculation logic
;hotstrings("i)\.(Y|T|M|W|N|H)(\+|\-)([\d]+)(\s)","complexDateLogic")
;handle simple logic: only trigger off certain end chars
; without changing Hotstring Endchars for everyone else (don't want to trigger off of '.t-')
;hotstrings("i)\.(N|T)(\s)","simpleDateLogic")
ComplexDateLogic:
;unpack variables into locals
time := A_Now
type := ""
char := $1
sign := $2
offset := $3
LASTCHAR := $4 ;override last-char logic, re-send it here
StringUpper, char, char
;quit if we're here without the correct assumed variables
if (char="")
{
Return
}
if (sign="-")
{
offset*=-1
}
if (char="T")
{
time += offset, D
type := "ShortDate"
}
else if (char="W")
{
time += offset*7, D
type := "ShortDate"
}
else if (char="M")
{
years:=Ceil((offset+A_MM)/12)-1
months := offset-12*years
time+=(months*100000000)+(years*10000000000)
type := "ShortDate"
}
else if (char="Y")
{
time+=(offset*10000000000)
type := "ShortDate"
}
else if (char="N")
{
time += offset, M
type := "Time"
}
else if (char="H")
{
time += offset, H
type := "Time"
}
;catch any parsing errors
if (type="")
{
MsgBox ERROR: char>%char% | sign>%sign% | offset>%offset% | type>%type%
}
if (time < 0)
{
MsgBox Cannot display B.C.E. date
Return
}
else
{
FormatTime, timeString, %time%, %type%
SendInput %timeString%%LASTCHAR%
}
Return
SimpleDateLogic:
type := ""
char := $1
LASTCHAR := $2 ;override last-char logic, re-send it here
StringUpper, char, char
if (char="N")
{
type := "Time"
}
if (char="T")
{
type := "ShortDate"
}
FormatTime, timeString, %A_Now%, %type%
SendInput %timeString%%LASTCHAR%
Return
PieceNextDay:
piece:=SubStr($1,1,3)
StringUpper, piece, piece
LASTCHAR:=$6
if (piece="SUN")
{
date:=NextDay(1)
}
else if (piece="MON")
{
date:=NextDay(2)
}
else if (piece="TUE")
{
date:=NextDay(3)
}
else if (piece="WED")
{
date:=NextDay(4)
}
else if (piece="THU")
{
date:=NextDay(5)
}
else if (piece="FRI")
{
date:=NextDay(6)
}
else if (piece="SAT")
{
date:=NextDay(7)
}
else
{
MsgBox % "Error parsing date:" . $1
Return
}
SendInput %date%%LASTCHAR%
Return
NextDay(day)
{
if (day<1 OR day>7)
{
Return
}
offset:=(day-A_WDay)
time:=A_Now
If (offset<1)
{
offset+=7
}
time += offset, D
FormatTime, timeString, %time%, ShortDate
Return %timeString%
}