mname = [ "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" ]; mlength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; function lowerCase(s) { for(local i = 0; i < sizeof(s); i++) { if(s[i] >= 'A' && s[i] <= 'Z') { s[i] += 'a' - 'A'; } } return s; } function day2num(date) { local parts = split(date, "-"); // find out which day of the month we have local days = eval(parts[0]); if(typeof days != "int") { message("Invalid day in " + date); return 0; } // make month lower case lowerCase(parts[1]); // add days from previous months for(local month = 0; month < sizeof mname; month++) { if(mname[month] == parts[1]) { // we have found the requested month, return result return days; } days += mlength[month]; } message("No month found in " + date); return 0; } function num2day(num) { // first check validity of input if(num < 1) { num = 1; } if(num > 365) { num = 365; } local month = 0; while(num > mlength[month]) { num -= mlength[month++]; } // we are at the month, but we don't want "12.4-feb" return round(num) + "-" + mname[month]; }