Работа с компонентами NSDate в Swift

У меня есть дата, которую мне нужно разбить на некоторые компоненты. например

let components = NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitHour
let date = calendar.components(components, fromDate: aDate, toDate: NSDate(), options: nil)
var dateToPrint = "\(date.day) days  \(date.hour) hours"

dateToPrint будет количество дней и часов от aDate до настоящего времени. Но если я хочу количество недель вместо дней

let components = NSCalendarUnit.CalendarUnitWeek | NSCalendarUnit.CalendarUnitHour
let date = calendar.components(components, fromDate: aDate, toDate: NSDate(), options: nil)
var dateToPrint = "\(date.week) weeks \(date.hour) hours"

date.week не существует. Итак, как я мог это решить?

Ответ 1

Xcode 8.3.2 • Swift 3.1

extension Date {
    func xDays(_ x: Int) -> Date {
        return Calendar.current.date(byAdding: .day, value: x, to: self)!
    }
    func xWeeks(_ x: Int) -> Date {
        return Calendar.current.date(byAdding: .weekOfYear, value: x, to: self)!
    }
    var weeksHoursFromToday: DateComponents {
        return Calendar.current.dateComponents( [.weekOfYear, .hour], from: self, to: Date())
    }
    var relativeDateString: String {
        var result = ""
        if let weeks = weeksHoursFromToday.weekOfYear,
            let hours = weeksHoursFromToday.hour,
            weeks > 0 {
            result +=  "\(weeks) week"
            if weeks > 1 { result += "s" }
            if hours > 0 { result += " and " }
        }
        if let hours = weeksHoursFromToday.hour, hours > 0 {
            result +=  "\(hours) hour"
            if hours > 1 { result += "s" }
        }
        return result
    }
}

let today       = Date()                  // "May 1, 2017, 9:29 PM"
let yesterday   = Date().xDays(-1)        // "Apr 30, 2017, 9:29 PM"
let twoWeeksAgo = Date().xWeeks(-2)       // "Apr 17, 2017, 9:29 PM"
let anotherDate = DateComponents(calendar: .current, year: 2013, month: 12, day: 4).date!  // "Dec 4, 2013, 12:00 AM"
let anotherDate2 = DateComponents(calendar: .current, year: 2012, month: 12, day: 3).date!  // "Dec 3, 2012, 12:00 AM"


yesterday.relativeDateString          // "24 hours"
twoWeeksAgo.relativeDateString        // "2 weeks"
anotherDate.relativeDateString        // "177 weeks and 141 hours"
anotherDate2.relativeDateString       // "230 weeks and 21 hours"
yesterday.relativeDateString          // "24 hours"
twoWeeksAgo.relativeDateString        // "2 weeks"
anotherDate.relativeDateString              // "177 weeks and 141 hours"
anotherDate2.relativeDateString              // "230 weeks and 21 hours"

Ответ 2

Мне понравился API в Leo solution и использовал его. Однако я столкнулся с проблемой, когда я ее запустил (13 июня 2015 г. 9:33 утра PST). Симптомы:

  • Когда дата будет в будущем, функция xFromToday вернется результаты для - (t-delta) (например, в течение 1 месяца в будущем Функции XFromToday вернутся (0, -4, -29, -719, -43199) для x = (месяц, неделя, дни, часы, минуты). Строка relativeDates вернет "1 неделя с сегодняшнего дня"

  • Когда дата предшествует, результаты будут для -t, кроме   для относительной строки даты. Например, в течение одного месяца в прошлом я   (1, 4, 31, 744, 44640). Относительная строка даты: "4 недели   и 744 часа"

Я не могу вставить тестовый результат из-за конфиденциальности, но код с NSDate.test() вставлен. У него также есть немного других вещей, заимствованных из другого сообщения (цитируется в коде) и некоторых материалов форматирования, которые я написал.

import Foundation

// https://stackoverflow.com/questions/27339072/working-with-nsdate-components-in-swift

// **** Use with caution may not do what you expect. See the stackoverflow post above.  *******

public extension NSDate {


    func xDays(x:Int) -> NSDate {
        return NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitDay, value: x, toDate: self, options: nil)!
    }
    func xWeeks(x:Int) -> NSDate {
        return NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitWeekOfYear, value: x, toDate: self, options: nil)!
    }
    func xMonths(x:Int) -> NSDate {
        return NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitMonth, value: x, toDate: self, options: nil)!
    }
    func xMins(x:Int) -> NSDate {
        return NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitMinute, value: x, toDate: self, options: nil)!
    }
    func xHours(x:Int) -> NSDate {
        return NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitHour, value: x, toDate: self, options: nil)!
    }
    var hoursFromToday: Int{
        return NSCalendar.currentCalendar().components(.CalendarUnitHour, fromDate: self, toDate: NSDate(), options: nil).hour
    }
    var weeksFromToday: Int{
        return NSCalendar.currentCalendar().components(.CalendarUnitWeekOfYear, fromDate: self, toDate: NSDate(), options: nil).weekOfYear
    }
    var daysFromToday: Int{
        return NSCalendar.currentCalendar().components(.CalendarUnitDay, fromDate: self, toDate: NSDate(), options: nil).day
    }
    var monthsFromToday: Int{
        return NSCalendar.currentCalendar().components(.CalendarUnitMonth, fromDate: self, toDate: NSDate(), options: nil).month
    }
    var minsFromToday: Int{
        return NSCalendar.currentCalendar().components(.CalendarUnitMinute, fromDate: self, toDate: NSDate(), options: nil).minute
    }
    var relativeDateString: String {
        if weeksFromToday > 0 { return weeksFromToday > 1 ? "\(weeksFromToday) weeks and \(hoursFromToday) hours" : "\(weeksFromToday) week and \(hoursFromToday) hours"   }
        if hoursFromToday > 0 { return hoursFromToday > 1 ? "\(hoursFromToday) hours" : "\(hoursFromToday) hour"   }
        return ""
    }

    //Date Comparisions
    //https://stackoverflow.com/questions/26198526/nsdate-comparison-using-swift  


    func isGreaterThanDate(dateToCompare : NSDate) -> Bool
    {
        //Declare Variables
        var isGreater = false

        //Compare Values
        if self.compare(dateToCompare) == NSComparisonResult.OrderedDescending
        {
            isGreater = true
        }

        //Return Result
        return isGreater
    }

    func isLessThanDate(dateToCompare : NSDate) -> Bool
    {
        //Declare Variables
        var isLess = false

        //Compare Values
        if self.compare(dateToCompare) == NSComparisonResult.OrderedAscending
        {
            isLess = true
        }

        //Return Result
        return isLess
    }




    // Date printing converstions




    var dayMonthYear: String {
        let dateMonthYearFormatter: NSDateFormatter = NSDateFormatter()
        let currentLocale: NSLocale = NSLocale.currentLocale()
        let dateMonthYearFormatString: NSString! = NSDateFormatter.dateFormatFromTemplate("EdMMMyyyy",options: 0, locale: currentLocale)
        dateMonthYearFormatter.dateFormat = dateMonthYearFormatString as! String
        return dateMonthYearFormatter.stringFromDate(self)
    }

    var timeDayMonthYear: String {
        let dateMonthYearFormatter: NSDateFormatter = NSDateFormatter()
        let currentLocale: NSLocale = NSLocale.currentLocale()
        let dateMonthYearFormatString: NSString! = NSDateFormatter.dateFormatFromTemplate("EdMMMyyyy' ' HH':'mm",options: 0, locale: currentLocale)
        dateMonthYearFormatter.dateFormat = dateMonthYearFormatString as! String
        return dateMonthYearFormatter.stringFromDate(self)
    }


    var hourMin: String {
        let hourMinFormatter = NSDateFormatter();
        hourMinFormatter.dateFormat = "HH:mm"
        return hourMinFormatter.stringFromDate(self)
    }

    static func rfc3339DateFormatter() -> NSDateFormatter {
        let rfc3339DateFormatterRet = NSDateFormatter()
        let enUSPOSIXLocale: NSLocale = NSLocale(localeIdentifier: "en_US_POSIX")
        rfc3339DateFormatterRet.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"
        rfc3339DateFormatterRet.locale = enUSPOSIXLocale
        rfc3339DateFormatterRet.timeZone = NSTimeZone(forSecondsFromGMT: 0)
        return rfc3339DateFormatterRet
    }


    var rfcString: String {
        return NSDate.rfc3339DateFormatter().stringFromDate(self)
    }
    func rfcDate(rfcString: String) -> NSDate {
    return NSDate.rfc3339DateFormatter().dateFromString(rfcString)!
    }

    func changeDate(toDate: NSDate) -> NSDate {

        let rfcToDate = toDate.rfcString
        let rfcSelf = self.rfcString
        let toDateArray : [String] = rfcToDate.componentsSeparatedByString("T")
        let selfArray : [String] = rfcSelf.componentsSeparatedByString("T")
        return rfcDate(toDateArray[0]+"T"+selfArray[1])

    }

    static func test(months: Int = 0, weeks: Int = 0, days: Int = 0, hrs: Int = 0, mins: Int = 0) {

        NSLog("****************** Start Testing of NSDate **************************")
        NSLog("Inputs: months:\(months) weeks:\(weeks) days:\(days) hrs: \(hrs) mins: \(mins)")
        var today = NSDate()
        NSLog("Today is: \(today.timeDayMonthYear)")

        var monthsFromToday = today.xMonths(months)
        NSLog("**  \(months) months from today: \(monthsFromToday.timeDayMonthYear)")
        NSLog("monthsFromToday returns: \(monthsFromToday.monthsFromToday)");
        NSLog("weeksFromToday returns: \(monthsFromToday.weeksFromToday)");
        NSLog("daysFromToday returns: \(monthsFromToday.daysFromToday)");
        NSLog("hoursFromToday returns: \(monthsFromToday.hoursFromToday)");
        NSLog("minsFromToday returns: \(monthsFromToday.minsFromToday)");
        NSLog("relativeDateString returns: \(monthsFromToday.relativeDateString)")

        var weeksFromToday = today.xWeeks(weeks)
        NSLog("**  \(weeks) weeks from today: \(weeksFromToday.timeDayMonthYear)")
        NSLog("weeksFromToday returns: \(weeksFromToday.weeksFromToday)");
        NSLog("relativeDateString returns: \(weeksFromToday.relativeDateString)")


        var daysFromToday = today.xDays(days)
        NSLog("**  \(days) days from today: \(daysFromToday.timeDayMonthYear)")
        NSLog("daysFromToday returns: \(daysFromToday.daysFromToday)");
        NSLog("relativeDateString returns: \(daysFromToday.relativeDateString)")

        var hrsFromToday = today.xHours(hrs)
        NSLog("**  \(hrs) hours from today: \(hrsFromToday.timeDayMonthYear)")
        NSLog("hoursFromToday returns: \(hrsFromToday.hoursFromToday)");
        NSLog("relativeDateString returns: \(hrsFromToday.relativeDateString)")

        var minsFromToday = today.xMins(mins)
        NSLog("**  \(mins) minutes from today: \(minsFromToday.timeDayMonthYear)")
        NSLog("minsFromToday returns: \(minsFromToday.minsFromToday)");
        NSLog("relativeDateString returns: \(minsFromToday.relativeDateString)")




        NSLog("__________________ End Testing of NSDate    _________________________")

    }
}

Вот "исправление", которое я сделал. Я добавил функцию santizedDates(), которая возвращает даты "от" и "до", и множитель знака (+ 1/-1). Смещение в 1 минуту добавляется к дате, если сравнение было в будущем. Он работает для тестового примера. Также производит корректный и понятный для пользователя вывод из relativeDateString (capitalizeFirst: Bool = false), например: "сегодня, 1 час 1 минута в прошлом". Я поставил вопрос о том, почему это происходит в первую очередь здесь:

NSCalendar.components(). минута, возвращающая несогласованные значения

import Foundation

// https://stackoverflow.com/questions/27339072/working-with-nsdate-components-in-swift


public extension NSDate {


    func xDays(x:Int) -> NSDate {
        return NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitDay, value: x, toDate: self, options: nil)!
    }
    func xWeeks(x:Int) -> NSDate {
        return NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitWeekOfYear, value: x, toDate: self, options: nil)!
    }
    func xMonths(x:Int) -> NSDate {
        return NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitMonth, value: x, toDate: self, options: nil)!
    }
    func xMins(x:Int) -> NSDate {

        return NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitMinute, value: x, toDate: self, options: nil)!
    }
    func xHours(x:Int) -> NSDate {
        return NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitHour, value: x, toDate: self, options: nil)!
    }
    var hoursFromToday: Int{

        var fromDate: NSDate = self
        var toDate: NSDate = NSDate()
        var sign: Int = -1
        (fromDate,toDate, sign) = self.sanitizedDates()

        return (sign * NSCalendar.currentCalendar().components(.CalendarUnitHour, fromDate: fromDate, toDate: toDate, options: nil).hour)
    }
    var weeksFromToday: Int{


        var fromDate: NSDate = self
        var toDate: NSDate = NSDate()
        var sign: Int = -1
        (fromDate,toDate,sign) = self.sanitizedDates()

        return (sign * NSCalendar.currentCalendar().components(.CalendarUnitWeekOfYear, fromDate: fromDate, toDate: toDate, options: nil).weekOfYear)
    }


    var daysFromToday: Int{

        var fromDate: NSDate = self
        var toDate: NSDate = NSDate()
        var sign: Int = -1
        (fromDate,toDate, sign) = self.sanitizedDates()


        return (sign * NSCalendar.currentCalendar().components(.CalendarUnitDay, fromDate: fromDate, toDate: toDate, options: nil).day)
    }
    var monthsFromToday: Int{


        var fromDate: NSDate = self
        var toDate: NSDate = NSDate()
        var sign: Int = -1
        (fromDate,toDate, sign) = self.sanitizedDates()

        return (sign * NSCalendar.currentCalendar().components(.CalendarUnitMonth, fromDate: fromDate, toDate: toDate, options: nil).month)

    }
    var minsFromToday: Int{


        var fromDate: NSDate = self
        var toDate: NSDate = NSDate()
        var sign: Int = -1
        var offset: Int = 0
        (fromDate,toDate,sign) = self.sanitizedDates()


        return ( sign * NSCalendar.currentCalendar().components(.CalendarUnitMinute, fromDate: fromDate, toDate: toDate, options: nil).minute)
    }

    func relativeDateString(capitalizeFirst:Bool = false) -> String {
        let days: Int = daysFromToday
        let mins: Int = minsFromToday % 60

        let tense: String = (minsFromToday > 0) ? " in the future" : " in the past"
        let hrs: Int =  hoursFromToday % 24
        var retString  = (capitalizeFirst) ? "Now" : "now"
        if(minsFromToday != 0) {
            if(days == 0) {
                retString = (capitalizeFirst) ? "Today" : "today"
                retString = (mins != 0 || hrs != 0) ? retString+"," : retString
            }
            else {
                let absDays = abs(days)
                retString = "\(absDays)"
                retString += (absDays > 1) ? " days" : " day"
            }
        if(hrs != 0) {
          let absHrs = abs(hrs)
             retString += " \(absHrs)"
            retString += (absHrs > 1) ? " hours" : " hour"
         }

            if(mins != 0) {
                let absMins = abs(mins)
                retString += " \(absMins)"
                retString += (absMins > 1) ? " minutes" : " minute"
            }

        retString += tense
        }

       return retString
    }

    //Date Comparisons
    //https://stackoverflow.com/questions/26198526/nsdate-comparison-using-swift  


    func isGreaterThanDate(dateToCompare : NSDate) -> Bool
    {
        //Declare Variables
        var isGreater = false

        //Compare Values
        if self.compare(dateToCompare) == NSComparisonResult.OrderedDescending
        {
            isGreater = true
        }

        //Return Result
        return isGreater
    }

    func isLessThanDate(dateToCompare : NSDate) -> Bool
    {
        //Declare Variables
        var isLess = false

        //Compare Values
        if self.compare(dateToCompare) == NSComparisonResult.OrderedAscending
        {
            isLess = true
        }

        //Return Result
        return isLess
    }




    // Date printing converstions




    var dayMonthYear: String {
        let dateMonthYearFormatter: NSDateFormatter = NSDateFormatter()
        let currentLocale: NSLocale = NSLocale.currentLocale()
        let dateMonthYearFormatString: NSString! = NSDateFormatter.dateFormatFromTemplate("EdMMMyyyy",options: 0, locale: currentLocale)
        dateMonthYearFormatter.dateFormat = dateMonthYearFormatString as! String
        return dateMonthYearFormatter.stringFromDate(self)
    }

    var timeDayMonthYear: String {
        let dateMonthYearFormatter: NSDateFormatter = NSDateFormatter()
        let currentLocale: NSLocale = NSLocale.currentLocale()
        let dateMonthYearFormatString: NSString! = NSDateFormatter.dateFormatFromTemplate("EdMMMyyyy' ' HH':'mm",options: 0, locale: currentLocale)
        dateMonthYearFormatter.dateFormat = dateMonthYearFormatString as! String
        return dateMonthYearFormatter.stringFromDate(self)
    }


    var hourMin: String {
        let hourMinFormatter = NSDateFormatter();
        hourMinFormatter.dateFormat = "HH:mm"
        return hourMinFormatter.stringFromDate(self)
    }

    static func rfc3339DateFormatter() -> NSDateFormatter {
        let rfc3339DateFormatterRet = NSDateFormatter()
        let enUSPOSIXLocale: NSLocale = NSLocale(localeIdentifier: "en_US_POSIX")
        rfc3339DateFormatterRet.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"
        rfc3339DateFormatterRet.locale = enUSPOSIXLocale
        rfc3339DateFormatterRet.timeZone = NSTimeZone(forSecondsFromGMT: 0)
        return rfc3339DateFormatterRet
    }


    var rfcString: String {
        return NSDate.rfc3339DateFormatter().stringFromDate(self)
    }
    func rfcDate(rfcString: String) -> NSDate {
    return NSDate.rfc3339DateFormatter().dateFromString(rfcString)!
    }

    func changeDate(toDate: NSDate) -> NSDate {

        let rfcToDate = toDate.rfcString
        let rfcSelf = self.rfcString
        let toDateArray : [String] = rfcToDate.componentsSeparatedByString("T")
        let selfArray : [String] = rfcSelf.componentsSeparatedByString("T")
        return rfcDate(toDateArray[0]+"T"+selfArray[1])

    }

    private  func sanitizedDates() -> (fromDate: NSDate, toDate: NSDate, sign: Int ) {
        var toDate: NSDate = self
        var fromDate: NSDate = NSDate()
        var sign: Int = 1
        // For toDates in the past, results are reasonable, except for sign. 
        //In future dates, we to flip dates to make them past dates and add 1 minute for unknown reason.
        if(toDate.isGreaterThanDate(fromDate)) {
           // NSLog("****** Flipping dates ********")
            toDate = fromDate.xMins(-1) // In this case, the results are consistently shorter by a minute
            fromDate = self
            sign  = -1
        }
        return (fromDate,toDate,sign)

    }

    static func test(months: Int = 0, weeks: Int = 0, days: Int = 0, hrs: Int = 0, mins: Int = 0) {

        NSLog("****************** Start Testing of NSDate **************************")
        NSLog("Inputs: months:\(months) weeks:\(weeks) days:\(days) hrs: \(hrs) mins: \(mins)")
        var today = NSDate()
        NSLog("Today is: \(today.timeDayMonthYear)")

        var monthsFromToday = today.xMonths(months)
        NSLog("**  \(months) months from today: \(monthsFromToday.timeDayMonthYear)")
        NSLog("monthsFromToday returns: \(monthsFromToday.monthsFromToday)");
        NSLog("weeksFromToday returns: \(monthsFromToday.weeksFromToday)");
        NSLog("daysFromToday returns: \(monthsFromToday.daysFromToday)");
        NSLog("hoursFromToday returns: \(monthsFromToday.hoursFromToday)");
        NSLog("minsFromToday returns: \(monthsFromToday.minsFromToday)");
        NSLog("relativeDateString returns: \(monthsFromToday.relativeDateString())")

        var weeksFromToday = today.xWeeks(weeks)
        NSLog("**  \(weeks) weeks from today: \(weeksFromToday.timeDayMonthYear)")
        NSLog("weeksFromToday returns: \(weeksFromToday.weeksFromToday)");
        NSLog("relativeDateString returns: \(weeksFromToday.relativeDateString(capitalizeFirst:true))")
        NSLog("minsFromToday returns: \(weeksFromToday.minsFromToday)");
        NSLog("monthsFromToday returns: \(weeksFromToday.monthsFromToday)");
        NSLog("weeksFromToday returns: \(weeksFromToday.weeksFromToday)");
        NSLog("daysFromToday returns: \(weeksFromToday.daysFromToday)");
        NSLog("hoursFromToday returns: \(weeksFromToday.hoursFromToday)");
        NSLog("minsFromToday returns: \(weeksFromToday.minsFromToday)");




        var daysFromToday = today.xDays(days)
        NSLog("**  \(days) days from today: \(daysFromToday.timeDayMonthYear)")
        NSLog("daysFromToday returns: \(daysFromToday.daysFromToday)");
        NSLog("relativeDateString returns: \(daysFromToday.relativeDateString())")
        NSLog("minsFromToday returns: \(daysFromToday.minsFromToday)");
        NSLog("monthsFromToday returns: \(daysFromToday.monthsFromToday)");
        NSLog("weeksFromToday returns: \(daysFromToday.weeksFromToday)");
        NSLog("daysFromToday returns: \(daysFromToday.daysFromToday)");
        NSLog("hoursFromToday returns: \(daysFromToday.hoursFromToday)");
        NSLog("minsFromToday returns: \(daysFromToday.minsFromToday)");




        var hrsFromToday = today.xHours(hrs)
        NSLog("**  \(hrs) hours from today: \(hrsFromToday.timeDayMonthYear)")
        NSLog("hoursFromToday returns: \(hrsFromToday.hoursFromToday)");
        NSLog("minsFromToday returns: \(hrsFromToday.minsFromToday)");
        NSLog("monthsFromToday returns: \(hrsFromToday.monthsFromToday)");
        NSLog("weeksFromToday returns: \(hrsFromToday.weeksFromToday)");
        NSLog("daysFromToday returns: \(hrsFromToday.daysFromToday)");
        NSLog("hoursFromToday returns: \(hrsFromToday.hoursFromToday)");
        NSLog("minsFromToday returns: \(hrsFromToday.minsFromToday)");






        NSLog("relativeDateString returns: \(hrsFromToday.relativeDateString(capitalizeFirst:true))")

        var minsFromToday = today.xMins(mins)
        NSLog("**  \(mins) minutes from today: \(minsFromToday.timeDayMonthYear)")
        NSLog("minsFromToday returns: \(minsFromToday.minsFromToday)");
        NSLog("monthsFromToday returns: \(minsFromToday.monthsFromToday)");
        NSLog("weeksFromToday returns: \(minsFromToday.weeksFromToday)");
        NSLog("daysFromToday returns: \(minsFromToday.daysFromToday)");
        NSLog("hoursFromToday returns: \(minsFromToday.hoursFromToday)");
        NSLog("minsFromToday returns: \(minsFromToday.minsFromToday)");


        NSLog("relativeDateString returns: \(minsFromToday.relativeDateString())")




        NSLog("__________________ End Testing of NSDate    _________________________")

    }
}

Ответ 3

Вам понадобится сделать еще одну переменную, называемую "календарь" (объект NSCalendar), и использовать метод init "currentCalendar". Когда у вас есть определенный объект календаря, вызовите метод в календаре rangeOfUnit: NSWeekCalendarUnit inUnit: NSMonthCalendarUnit forDate: date. Затем сделайте NSInteger с именем amountOfWeeks, равным диапазону, возвращаемому выше. Длина диапазона, возвращаемого функцией, будет числом недель в этом месяце.

Ответ 4

Не уверен, чего вы хотите, но есть weekday, weekdayOrdinal, weekOfMonth и weekOfYear. (week устарел.)