lib/net/imap/date.rb in imap_processor-1.7 vs lib/net/imap/date.rb in imap_processor-1.8.0

- old
+ new

@@ -1,13 +1,30 @@ +require "time" -class Time +class Time # :nodoc: + IMAPDATE = "%d-%b-%Y" # :nodoc: + IMAPDATETIME = "%d-%b-%Y %H:%M %Z" # :nodoc: ## + # Parse an IMAP date formatted string into a Time. + + def self.imapdate str + Time.strptime str, IMAPDATE + end + + ## + # Parse an IMAP datetime formatted string into a Time. + + def self.imapdatetime str + Time.strptime str, IMAPDATETIME + end + + ## # Formats this Time as an IMAP-style date. def imapdate - strftime '%d-%b-%Y' + strftime IMAPDATE end ## # Formats this Time as an IMAP-style datetime. # @@ -15,10 +32,15 @@ # almost but not quite RFC 822 compliant. #-- # Go Mr. Leatherpants! def imapdatetime - strftime '%d-%b-%Y %H:%M %Z' + strftime IMAPDATETIME end -end + ## + # Format a date into YYYY-MM, common for mailbox extensions. + def yyyy_mm + strftime("%Y-%m") + end +end