Skip to content

Instantly share code, notes, and snippets.

@railsbridge
Created September 8, 2009 19:13
Show Gist options
  • Save railsbridge/183151 to your computer and use it in GitHub Desktop.
Save railsbridge/183151 to your computer and use it in GitHub Desktop.
def self.parse(value)
date_value = nil
# java.util.GregorianCalendar[time=1251874800000,areFieldsSet=true,areAllFieldsSet=true,
lenient=true,zone=sun.util.calendar.ZoneInfo[id="US/Pacific",offset=-28800000,dstSavings=3600000,
useDaylight=true,transitions=185,lastRule=java.util.SimpleTimeZone[id=US/Pacific,offset=-28800000,
dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,
startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,
endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2009,MONTH=8,
WEEK_OF_YEAR=36,WEEK_OF_MONTH=1,DAY_OF_MONTH=2,DAY_OF_YEAR=245,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=1,
AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=-28800000,
DST_OFFSET=3600000]
if value =~ /^java.*,YEAR=(\d*).*,MONTH=(\d*).*,DAY_OF_MONTH=(\d*).*/
date_value = Date.new($1.to_i, $2.to_i, $3.to_i)
end
# Jul 21, 2009
if !date_value && value =~ /^[Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec].*/
date_value = Date.parse(value) rescue nil
end
date_value ? date_value : value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment