Last active
March 1, 2019 16:17
-
-
Save kubadlo/17d82fe7a069bdc7f68ca8c27b84d38e to your computer and use it in GitHub Desktop.
Autohotkey function to generate Slovak birth number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Function to generate birth numbers [Win + Shift + B] | |
#+b::GenerateBirthNum() | |
GenerateBirthNum() | |
{ | |
Gender: | |
Random, Gender, 0, 1 | |
Year: | |
Random, Year, 1970, FormatTime, CurrentDateTime,, yyyy | |
ShortYear := Mod(Year, 100) < 10 ? 0 . Mod(Year, 100) : Mod(Year, 100) | |
Month: | |
Random, Month, 1, 12 | |
Month := Gender == 1 ? Month + 50 : Month | |
Month := Month < 10 ? 0 . Month : Month | |
Day: | |
Random, Day, 1, LastDayOfMonth(Month, Year) | |
Day := Day < 10 ? 0 . Day : Day | |
Sequence: | |
Random, Sequence, 0, 999 | |
if (Sequence < 10) | |
{ | |
Sequence := 00 . Sequence | |
} | |
else if (Sequence < 100) | |
{ | |
Sequence := 0 . Sequence | |
} | |
BirthNumModulo := Mod(ShortYear . Month . Day . Sequence, 11) | |
ControlNumber := BirthNumModulo == 10 ? 0 : BirthNumModulo | |
SendInput % ShortYear . Month . Day . "/" . Sequence . ControlNumber | |
Exit | |
} | |
LastDayOfMonth(Month, Year) | |
{ | |
if (Month == 4 || Month == 6 || Month == 9 || Month == 11) | |
{ | |
return 30 | |
} | |
if (Month == 2) | |
{ | |
return IsLeapYear(Year) ? 29 : 28 | |
} | |
return 31 | |
} | |
IsLeapYear(Year) | |
{ | |
return Mod(Year, 4) == 0 && (Mod(Year, 100) != 0 || Mod(Year, 400) == 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment