Erster Tag einer Kalenderwoche

Manchmal ist es notwendig den ersten Tag einer Kalenderwoche zu identifizieren. Ruby liefert schon einige Hilfsmittel hierfür, aber es gibt keine direkte Methode dafür. Hier ist eine Möglichkeit zur Berechnung des ersten Tages (Montag) einer Kalenderwoche:

def week_to_date(week, year)
  date = Date.parse("01-01-"+year)
  if date.cwday == 1
    x = 0;
  else
    x = 8-date.cwday
  end
    date+x+(7*(week-1))
 end
This entry was posted in ruby. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Security Code: