The submitted form was invalid. Try submitting again.
Following (below!) my function it its present state. It is working fine, but I didn't go completely for your solution - here's why:
Code: Select all
date := Format('{}-{:02}-{:02.0f}', part[3], moNum(part[2]), part[1])
For the life of me I cannot figure out what this line does, nor how to get any variant of it to work for me. Of course I've tried to decipher
Format, but what you are formatting, and how you are formatting it?
Your function moNum I somewhat understand
Code: Select all
moNum(moName) {
For n, mo in newNumMonth {
MsgBox n
If SubStr(moName, 1, 3) ~= 'i)' mo //WHAT IS HAPPENING HERE?
Return n
}
but at "//" I don't understand the syntax. Also it seems, your function will go through your array 'newNumMonth' several times, in case of 'Dec" 12 times?
Is my approach not more efficient with a single lookup?
Code: Select all
#Requires AutoHotkey v2.0
#Include "F:\data\ahk\library\udf.ahk"
;#Include "F:\data\ahk\library\UDF-test.ahk"
/*--------------------------------------------------------------
PURPOSE:
Convert a one single _selected date_ (German or English)
to a format like "YYYY-MM-DD" (ISO 8601) like so
German:
"22. Dezember 1988" -> "1988-12-22"
"22. Dez. 1988" -> "1988-12-22"
English:
"December 22, 1988" -> "1988-12-22"
"Dec 22, 1988" -> "1988-12-22"
VARIABLES
The following varibles are in use:
- monthNum
an object with 'month short' (Abbreviations for month names) and
their corresponding 'month numbers' like so
"Jun" -> "06"
"Mar" -> "03"
"Mär" -> "03"
- part
Array. Populated by StrSplit in 3 parts
part[1]: will hold the day of the date
part[2]: will hold the month of the date
part[3]: will hold the year of the date
- selectedDate
This is the selected date string which is parsed into
three parts (s.a.)
- use for readablity
currentDay -> part[1]
currentMonth -> part[2]
currentYear -> part[3]
- datePattern
Presently takes the value of "Deutsch" or "English"
Used to distinguish repsp. date patterns
- currentMonthNum
Takes the resp. number of the month ('May'->'05', 'Jun'->'06', asf)
--------------------------------------------------------------*/
F4:: {
/*--------------------------------------------------------------
Declaration of variables
--------------------------------------------------------------*/
local monthNum := {}
, part := []
, selectedDate := ''
, currentDay := ''
, currentMonth := ''
, currentYear := ''
, datePattern := ''
, currentMonthNum := ""
/*--------------------------------------------------------------
Declaration of variables
--------------------------------------------------------------*/
monthNum := {
Jan: "01",
Feb: "02",
Mar: "03",
Mär: "03",
Apr: "04",
May: "05",
Mai: "05",
Jun: "06",
Jul: "07",
Aug: "08",
Sep: "09",
Oct: "10",
Okt: "10",
Nov: "11",
Dec: "12",
Dez: "12"
}
; selectedDate := '29. December 1986'
; Copy the selected date safely to A_Clipboard
selectedDate := SimplyCopy()
; split the selcted date in 3 parts and assign accordingly
part := StrSplit(selectedDate, ' ')
; check if German or English
datePattern := IsNumber(SubStr(part[1], 1, 1)) ? "Deutsch" : "English"
switch datePattern {
case "Deutsch":
currentDay := part[1]
; currentDay may be succeeded by an "," or an "."
; so let's shorten currentDay by 1
currentDay := SubStr(currentDay, 1, StrLen(currentDay) - 1)
; currentDay may consist of only 1 digit. So let's check the length
; of the string: only if it is 1, let's add a "0"
StrLen(currentDay) = 1 ? currentDay := "0" . currentDay : currentDay
; for better readability let's assign 'part' to the appropriate
; variables
currentMonth := part[2]
case "English":
; In the English pattern part[1] will containt the months
currentMonth := part[1]
; In the English pattern part[2] will containt the day
currentDay := part[2]
; currentDay may be succeeded by an "," or an "."
; so let's shorten currentDay by 1
currentDay := SubStr(currentDay, 1, StrLen(currentDay) - 1)
; currentDay may consist of only 1 digit. So let's check the length
; of the string: only if it is 1, let's add a "0"
StrLen(currentDay) = 1 ? currentDay := "0" . currentDay : currentDay
}
; currentYear is in both patterns part[3]
currentYear := part[3]
; Get the first 3 characters (month short) of the currentMonth
currentMonth := SubStr(currentMonth, 1, 3)
; Look up the now abbreviated currentMonth in the monthNum-Obj
currentMonthNum := monthNum.%currentMonth%
; Copy the converted date safely to A_Clipboard
SaveInsert(currentYear . "-" . currentMonthNum . "-" . currentDay)
toot
}
Below also my present helper file and the UDF-"library" (A few UDF do not make a library, but it is a start and good place for them). Not finished yet. And this last function is not in there either.
Thank you for your help,
@mikeyww