<?xml version="1.0" encoding="UTF-8"?>
<codes type="array">
  <code>
    <code>var d = Date.parse(&quot;Fri, 4 Dec 2008 15:13:00 +0000&quot;);
var dateFunc = new Date();
var timeSince = dateFunc.getTime() - d;
var inSeconds = timeSince / 1000;
var inMinutes = timeSince / 1000 / 60;
var inHours = timeSince / 1000 / 60 / 60;
var inDays = timeSince / 1000 / 60 / 60 / 24;
var inYears = timeSince / 1000 / 60 / 60 / 24 / 365;

if(Math.round(inSeconds) == 1){
	document.write(&quot;1 second ago&quot;);
}
else if(inMinutes &lt; 1.01){
	document.write(Math.round(inSeconds) + &quot; seconds ago&quot;);
}

else if(Math.round(inMinutes) == 1){
	document.write(&quot;1 minute ago&quot;);
}
else if(inHours &lt; 1.01){
	document.write(Math.round(inMinutes) + &quot; minutes ago&quot;);
}

else if(Math.round(inHours) == 1){
	document.write(&quot;1 hour ago&quot;);
}
else if(inDays &lt; 1.01){
	document.write(Math.round(inHours) + &quot; hours ago&quot;);
}

else if(Math.round(inDays) == 1){
	document.write(&quot;1 day ago&quot;);
}
else if(inYears &lt; 1.01){
	document.write(Math.round(inDays) + &quot; days ago&quot;);
}

else if(Math.round(inYears) == 1){
	document.write(&quot;1 year ago&quot;);
}
else {
document.write(Math.round(inYears) + &quot; years ago&quot;);
}</code>
    <created-at type="datetime">2009-04-20T01:00:35Z</created-at>
    <description></description>
    <id type="integer">170</id>
    <language-id type="integer">19</language-id>
    <privated type="boolean">false</privated>
    <title>parse relative date</title>
    <updated-at type="datetime">2009-04-20T01:00:35Z</updated-at>
    <user-id type="integer">7</user-id>
  </code>
  <code>
    <code>require &quot;rubygems&quot;
require &quot;activesupport&quot;
require &quot;unicode&quot;

class String
  def as_time
    str = self.dup
    str.downcase!
    str.squish!
    str = Unicode.normalize_KD(self).gsub(/[^\x00-\x7F]/n,'')
    
    now = Time.now

    if str == 'hoje'
      Date.today.to_time
    elsif str == 'agora'
      Time.now
    elsif str == 'amanha'
      Date.tomorrow.to_time
    elsif str == 'ontem'
      Date.yesterday.to_time
    elsif str == 'anteontem'
      2.days.ago
    elsif str == 'depois de amanha'
      2.days.from_now
    elsif str =~ /^proxim[oa] (semana|dia|mes|ano)$/
      case $1
        when 'semana' then now.next_week
        when 'dia' then Date.tomorrow.to_time
        when 'mes' then now.next_month
        when 'ano' then now.next_year
      end
    elsif str =~ /^(mes|semana|ano) que vem/
      case $1
        when 'mes' then now.next_month
        when 'semana' then now.next_week
        when 'ano' then now.next_year
      end
    elsif str =~ /^(mes|semana|ano) passad[ao]/
      case $1
        when 'mes' then now.last_month
        when 'semana' then now.beginning_of_week
        when 'ano' then now.last_year
      end
    elsif str =~ /^de (tarde|manha|noite)/
      case $1
        when 'noite' then now.beginning_of_day + 20.hours
        when 'tarde' then now.beginning_of_day + 15.hours
        when 'manha' then now.beginning_of_day + 9.hours
      end
    elsif str =~ /^daqui h?a pouco/
      1.hour.from_now
    elsif str =~ /^daqui(?: h?a)? ([0-9]+) (dias?|mes(?:es)?|semanas?|anos?|horas?|minutos?)/
      num = $1.to_i
      interval = $2.gsub(/e?s$/, '')

      names = {
        'dia' =&gt; :day,
        'mes' =&gt; :month,
        'semana' =&gt; :week,
        'ano' =&gt; :year,
        'hora' =&gt; :hour,
        'minuto' =&gt; :minute
      }
      
      num.send(names[interval]).from_now
    end
  end
end</code>
    <created-at type="datetime">2008-07-02T00:19:29Z</created-at>
    <description></description>
    <id type="integer">9</id>
    <language-id type="integer">39</language-id>
    <privated type="boolean">false</privated>
    <title>Chronic-like in Portuguese</title>
    <updated-at type="datetime">2008-07-02T00:19:29Z</updated-at>
    <user-id type="integer">8</user-id>
  </code>
</codes>
