Created
November 12, 2010 10:29
-
-
Save trygvea/673956 to your computer and use it in GitHub Desktop.
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
// Konverter tekst: Tirsdag, ukenr 49, år 2006 | |
// til dato | |
Date gjettSlakteDato(String tekst, Date compareToDate) { | |
def ukedag = ["Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag", "Søndag"] | |
def split = tekst.split(",") | |
String d = ukedag.findIndexOf {it == split[0]} + 1 | |
String ww = split[1][-2..-1] | |
String y = split[2][-1] | |
return convertDateFormat(y+ww+d, compareToDate) | |
} | |
Date convertDateFormat(String ywwd, Date compareTo) { | |
Locale HAANDTERMINAL_LOCALE = new Locale("no", "NO") | |
int aar = Integer.parseInt(ywwd.substring(0,1)) | |
int ukenr = Integer.parseInt(ywwd.substring(1,3)) | |
int dagiuken = Integer.parseInt(ywwd.substring(3)) | |
Calendar cal = GregorianCalendar.getInstance(HAANDTERMINAL_LOCALE) | |
cal.setTime(compareTo) | |
int yearDiff = cal.get(Calendar.YEAR) % 10 - aar | |
cal.add(Calendar.YEAR, -yearDiff) | |
cal.set(Calendar.DAY_OF_WEEK, dagiuken % 7 + 1) | |
cal.set(Calendar.WEEK_OF_YEAR, ukenr) | |
return cal.getTime() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment