Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MsgBox, % EngToJapDate("2000.3.4")
- ExitApp
- ^+c::EngToJapDate(ClipboardGet())
- ^+v::JapToEngDate() ;ClipboardGet())
- ; Convert english to japanese
- EngToJapDate(date){
- ; Table containing the year/month/date of all emporors through 1868
- Static japYrArr := {1868:{month:9 ,day:8 ,name:"Meiji" }
- ,1912:{month:7 ,day:12 ,name:"Taisho" }
- ,1926:{month:12 ,day:25 ,name:"Showa" }
- ,1989:{month:1 ,day:8 ,name:"Heisei" } }
- ; Create vars
- result := ""
- ; Create an array from the year.month.day string
- dateArr := DateStripAndVerify(date)
- ; Loop through table
- for year, subArr in japYrArr
- {
- ; Check if date is larger
- If (dateArr.year > year)
- result := subArr.name " " (dateArr.Year - year)
- ; If date is equal, check if month is greater
- Else If (dateArr.year = year) && (dateArr.month > subArr.month)
- result := subArr.name " " (dateArr.Year - year)
- ; If date and month are equal, check if day is greater
- Else If (dateArr.year = year) && (dateArr.month = subArr.month) && (dateArr.day >= subArr.day)
- result := subArr.name " " (dateArr.Year - year)
- }
- Return result
- }
- JapToEngDate(){
- return result
- }
- DateStripAndVerify(date){
- dateArr := {}
- If RegExMatch(date, "(\d+)\D+(\d+)\D+(\d+)") {
- date := RegExReplace(date, "(\d+)\D+(\d+)\D+(\d+)", "$1.$2.$3")
- tmpArr := StrSplit(date, "."), dateArr.Year := tmpArr.1, dateArr.Month := tmpArr.2, dateArr.day := tmpArr.3
- Return dateArr
- }Else{
- MsgBox, Error!`n%date% is not a valid date.`nUse Year.Month.Day format.`nThe dots can be any non-numerical chracters.
- Exit
- }
- }
- ClipboardGet(){
- ; Back up clipboard
- clipBak := ClipboardAll
- ; Clear clipboard
- Clipboard := ""
- ; Send copy command
- SendInput, ^c
- ; Wait up to 1 second for text to appear on clipboard
- ClipWait, 1, 0
- ; If no text appears
- If (ErrorLevel){
- ; Throw an error and end the thread
- MsgBox, Error. No text was detected.
- Exit
- }
- ; If text appeared, save text
- result := Clipboard
- ; Restore clipboard
- Clipboard := clipBak
- ; Garbage cleanup
- clipBak := ""
- ; Return the copied date with the original clipboard still intact
- return result
- }
- ClipboardSend(){
- return result
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement