I'm wanting to use my Firebase database that has the values of a product i.e. lifespan (an integer not a date) and use it to compare the date in which the user has added the item i.e. 25/03/17, I'm not sure how to achieve this. Can somebody give me some advice. I believe it is to do with approximation, so if the liespan is equal 7 then the user should see 7 days and it would decrease each day, so basically a countdown. I've looked at NSDate documentation and the SwiftDate framework and do have a bit of knowledge on the methods I might need to use.
I have this example where it gets the engagement date and compares it with the wedding date, I'm thinking this is somewhat similar to what I want to try and achieve. However as this uses two dates and I want to use a date and an integer:
formatter.dateFormat = "dd/MM/yyyy"
let dateArray = message["message"] as! NSMutableArray
if let startTimeString = dateArray[0] as? String {
let weddingDate = formatter.dateFromString(startTimeString)
var engagementDate:NSDate? = nil
if let endTimeString = dateArray[1] as? String {
engagementDate = formatter.dateFromString(endTimeString)
}
let now = NSDate()
let totalEngagementTime = userCalender.components(.Day, fromDate: engagementDate!, toDate: weddingDate!, options: []).day
let daysFromEngagementUntilNow = userCalender.components(.Day, fromDate: engagementDate!, toDate: now, options: []).day
let percentage = (Double(daysFromEngagementUntilNow) / Double(totalEngagementTime)) * 100.00
let timeUntilWedding = userCalender.components(requestedComponent, fromDate: now, toDate: weddingDate!, options: [])
Hope I made sense, thank you in advance! :)