Advertisement
GroggyOtter

YearMonthDay version of J to E converter

Mar 4th, 2019
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MsgBox, % EngToJapDate("2000.3.4")
  2. ExitApp
  3.  
  4. ^+c::EngToJapDate(ClipboardGet())
  5. ^+v::JapToEngDate() ;ClipboardGet())
  6.  
  7. ; Convert english to japanese
  8. EngToJapDate(date){
  9.     ; Table containing the year/month/date of all emporors through 1868
  10.     Static japYrArr :=  {1868:{month:9  ,day:8  ,name:"Meiji"   }
  11.                         ,1912:{month:7  ,day:12 ,name:"Taisho"  }
  12.                         ,1926:{month:12 ,day:25 ,name:"Showa"   }
  13.                         ,1989:{month:1  ,day:8  ,name:"Heisei"  }   }
  14.    
  15.     ; Create vars
  16.     result  := ""
  17.     ; Create an array from the year.month.day string
  18.     dateArr := DateStripAndVerify(date)
  19.    
  20.     ; Loop through table
  21.     for year, subArr in japYrArr
  22.     {
  23.         ; Check if date is larger
  24.         If (dateArr.year > year)
  25.             result := subArr.name " " (dateArr.Year - year)
  26.         ; If date is equal, check if month is greater
  27.         Else If (dateArr.year = year) && (dateArr.month > subArr.month)
  28.             result := subArr.name " " (dateArr.Year - year)
  29.         ; If date and month are equal, check if day is greater
  30.         Else If (dateArr.year = year) && (dateArr.month = subArr.month) && (dateArr.day >= subArr.day)
  31.             result := subArr.name " " (dateArr.Year - year)
  32.     }
  33.    
  34.     Return result
  35. }
  36.  
  37. JapToEngDate(){
  38.    
  39.     return result
  40. }
  41.  
  42. DateStripAndVerify(date){
  43.     dateArr := {}
  44.     If RegExMatch(date, "(\d+)\D+(\d+)\D+(\d+)") {
  45.         date := RegExReplace(date, "(\d+)\D+(\d+)\D+(\d+)", "$1.$2.$3")
  46.         tmpArr := StrSplit(date, "."), dateArr.Year := tmpArr.1, dateArr.Month := tmpArr.2, dateArr.day := tmpArr.3
  47.         Return dateArr
  48.     }Else{
  49.         MsgBox, Error!`n%date% is not a valid date.`nUse Year.Month.Day format.`nThe dots can be any non-numerical chracters.
  50.         Exit
  51.     }
  52. }
  53.  
  54. ClipboardGet(){
  55.     ; Back up clipboard
  56.     clipBak := ClipboardAll
  57.     ; Clear clipboard
  58.     Clipboard := ""
  59.     ; Send copy command
  60.     SendInput, ^c
  61.     ; Wait up to 1 second for text to appear on clipboard
  62.     ClipWait, 1, 0
  63.     ; If no text appears
  64.     If (ErrorLevel){
  65.         ; Throw an error and end the thread
  66.         MsgBox, Error. No text was detected.
  67.         Exit
  68.     }
  69.     ; If text appeared, save text
  70.     result := Clipboard
  71.     ; Restore clipboard
  72.     Clipboard := clipBak
  73.     ; Garbage cleanup
  74.     clipBak := ""
  75.     ; Return the copied date with the original clipboard still intact
  76.     return result
  77. }
  78.  
  79. ClipboardSend(){
  80.    
  81.     return result
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement