Commit f3cc8e00 authored by Sgangele21's avatar Sgangele21
Browse files

Temporary fix for open/close logic. There is a crash that deals with forced...

Temporary fix for open/close logic. There is a crash that deals with forced unwrapping with start and end times.
parent 02f95d36
...@@ -224,7 +224,7 @@ ...@@ -224,7 +224,7 @@
}; };
CD81F5181DC0334600009FBD = { CD81F5181DC0334600009FBD = {
CreatedOnToolsVersion = 8.0; CreatedOnToolsVersion = 8.0;
DevelopmentTeam = N5GM564QWL; DevelopmentTeam = HYRMVFF8PJ;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
}; };
...@@ -513,14 +513,14 @@ ...@@ -513,14 +513,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = N5GM564QWL; DEVELOPMENT_TEAM = HYRMVFF8PJ;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)", "$(PROJECT_DIR)",
); );
INFOPLIST_FILE = WhatsOpen/Info.plist; INFOPLIST_FILE = WhatsOpen/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = space.srct.WhatsOpeniOS; PRODUCT_BUNDLE_IDENTIFIER = "space.srct.WhatsOpeniOS-sg";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0; SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
...@@ -534,14 +534,14 @@ ...@@ -534,14 +534,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = N5GM564QWL; DEVELOPMENT_TEAM = HYRMVFF8PJ;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)", "$(PROJECT_DIR)",
); );
INFOPLIST_FILE = WhatsOpen/Info.plist; INFOPLIST_FILE = WhatsOpen/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = space.srct.WhatsOpeniOS; PRODUCT_BUNDLE_IDENTIFIER = "space.srct.WhatsOpeniOS-sg";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0; SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
......
...@@ -116,7 +116,15 @@ class MainSchedule: Object, Mappable { ...@@ -116,7 +116,15 @@ class MainSchedule: Object, Mappable {
func mapping(map: Map){ func mapping(map: Map){
id <- map["id"] id <- map["id"]
openTimes <- map["open_times"] // This is a way around mapping to a list object
var openTimesList: [OpenTimes]?
openTimesList <- map["open_times"]
if let openTimesList = openTimesList {
for openTime in openTimesList {
self.openTimes.append(openTime)
}
}
//
lastModified <- map["modified"] lastModified <- map["modified"]
name <- map["name"] name <- map["name"]
validStart <- map["valid_start"] validStart <- map["valid_start"]
...@@ -127,6 +135,10 @@ class MainSchedule: Object, Mappable { ...@@ -127,6 +135,10 @@ class MainSchedule: Object, Mappable {
class SpecialSchedule: Object, Mappable { class SpecialSchedule: Object, Mappable {
var isValid: Bool {
return !(self.lastModified.isEmpty && self.name.isEmpty && self.validEnd.isEmpty && self.validStart.isEmpty)
}
convenience required init?(map: Map) { convenience required init?(map: Map) {
self.init() self.init()
} }
...@@ -165,8 +177,8 @@ class OpenTimes: Object, Mappable { ...@@ -165,8 +177,8 @@ class OpenTimes: Object, Mappable {
} }
func mapping(map: Map){ func mapping(map: Map){
schedule <- map["id"] schedule <- map["schedule"]
lastModified <- map["last_modified"] lastModified <- map["modified"]
startDay <- map["start_day"] startDay <- map["start_day"]
endDay <- map["end_day"] endDay <- map["end_day"]
startTime <- map["start_time"] startTime <- map["start_time"]
......
...@@ -32,7 +32,7 @@ class SRCTNetworkController: NSObject { ...@@ -32,7 +32,7 @@ class SRCTNetworkController: NSObject {
// Map function to iterate through each JSON tree // Map function to iterate through each JSON tree
let facilities = json!.map({ (json) -> Facility in let facilities = json!.map({ (json) -> Facility in
let facility = Facility() let facility = Facility()
let map = Map(mappingType: .fromJSON, JSON: json, toObject: true, context: facility, shouldIncludeNilValues: false) let map = Map(mappingType: .fromJSON, JSON: json, toObject: true, context: facility, shouldIncludeNilValues: true)
facility.mapping(map: map) facility.mapping(map: map)
// Look at this print statement, it shows everything // Look at this print statement, it shows everything
print(facility) print(facility)
......
...@@ -29,6 +29,9 @@ class Utilities: NSObject { ...@@ -29,6 +29,9 @@ class Utilities: NSObject {
} }
} else { } else {
if(isMainSchedule(facility:facility)) { if(isMainSchedule(facility:facility)) {
print(facility.mainSchedule?.openTimes.isEmpty)
print(facility.mainSchedule?.openTimes.count)
print(facility.mainSchedule?.openTimes)
if(!facility.mainSchedule!.openTimes.isEmpty) { if(!facility.mainSchedule!.openTimes.isEmpty) {
if today(facility: facility) != nil { if today(facility: facility) != nil {
let nowTime = time(facility) let nowTime = time(facility)
...@@ -46,7 +49,6 @@ class Utilities: NSObject { ...@@ -46,7 +49,6 @@ class Utilities: NSObject {
} }
} }
// print(facility.mainScheduleprint.name ," is ", open)
return open return open
} }
...@@ -60,23 +62,38 @@ class Utilities: NSObject { ...@@ -60,23 +62,38 @@ class Utilities: NSObject {
} }
static func getCurrentTime() -> Date { static func getCurrentTime() -> Date {
let date = Date() // let date = Date()
// let dateFormatter = DateFormatter()
// dateFormatter.locale = Locale(identifier: "ET")
// dateFormatter.timeZone = TimeZone.current
// dateFormatter.dateFormat = "HH:mm:ss.S"
// let convertedDate = dateFormatter.string(from: date)
// let currentDay = dateFormatter.date(from: convertedDate)
// print(currentDay)
let currentDate = Date()
// let calendar = Calendar.current
// let hour = calendar.component(.hour, from: currentDate)
// let minute = calendar.component(.minute, from: currentDate)
let dateFormatter = DateFormatter() let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "ET") dateFormatter.timeZone = TimeZone.current
dateFormatter.locale = Locale.current
dateFormatter.dateFormat = "HH:mm:ss" dateFormatter.dateFormat = "HH:mm:ss"
let convertedDate = dateFormatter.string(from: date)
let currentDay = dateFormatter.date(from: convertedDate) let stringDate = dateFormatter.string(from: currentDate)
return currentDay! let formattedDate = dateFormatter.date(from: stringDate)
print(formattedDate)
return formattedDate!
} }
//Gets the current day of the week. //Gets the current day of the week.
static func today(facility: Facility) -> OpenTimes? { static func today(facility: Facility) -> OpenTimes? {
let currentDay = getDayOfWeek() let currentDay = getDayOfWeek()
let day = currentDay
if(isMainSchedule(facility: facility)) { if(isMainSchedule(facility: facility)) {
for openTime in facility.mainSchedule!.openTimes { for openTime in facility.mainSchedule!.openTimes {
if(day! >= openTime.startDay && day! <= openTime.endDay) { if(currentDay! >= openTime.startDay && currentDay! <= openTime.endDay) {
return openTime return openTime
} }
} }
...@@ -87,25 +104,30 @@ class Utilities: NSObject { ...@@ -87,25 +104,30 @@ class Utilities: NSObject {
} }
// Converts our startTime and endTime to dates. // Converts our startTime and endTime to dates.
static func convertTime(_ facility: Facility) -> (startTime: Date, endTime: Date)? { static func getStartEndDates(_ facility: Facility) -> (startTime: Date, endTime: Date)? {
let formatter = DateFormatter() let today = self.today(facility: facility)
formatter.locale = Locale(identifier: "US_en") let startTime = today?.startTime
formatter.dateFormat = "HH:mm:ss" let endTime = today?.endTime
// TODO: This is a forced unwrapping, very dangerous, and needs to be fixed
let dateFormatter = DateFormatter() let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd" dateFormatter.timeZone = TimeZone.current
guard let startTime = dateFormatter.date(from: facility.mainSchedule!.validStart), let endTime = dateFormatter.date(from: facility.mainSchedule!.validEnd) else { return nil } dateFormatter.locale = Locale.current
dateFormatter.dateFormat = "HH:mm:ss"
let formattedStartTime = dateFormatter.date(from: startTime!)
// TODO: Error here
let formattedEndTimeDate = dateFormatter.date(from: endTime!)
return (startTime, endTime) guard let startTimeDate = formattedStartTime, let endTimeDate = formattedEndTimeDate else { return nil }
return (startTimeDate, endTimeDate)
} }
static func time(_ facility: Facility) -> Bool { static func time(_ facility: Facility) -> Bool {
var time = false var time = false
let nowTime = getCurrentTime() let nowTime = getCurrentTime()
// TODO: Check if this logic works // TODO: Check if this logic works
guard let startEnd = convertTime(facility) else { return false } guard let startEnd = getStartEndDates(facility) else { return false }
if(startEnd.startTime >= startEnd.endTime || nowTime >= startEnd.startTime && nowTime <= startEnd.endTime) { if(nowTime >= startEnd.startTime && nowTime <= startEnd.endTime) {
time = true time = true
} }
...@@ -119,7 +141,7 @@ class Utilities: NSObject { ...@@ -119,7 +141,7 @@ class Utilities: NSObject {
dateComponentsFormatter.allowedUnits = [.year,.month,.weekOfYear,.day,.hour,.minute,.second] dateComponentsFormatter.allowedUnits = [.year,.month,.weekOfYear,.day,.hour,.minute,.second]
dateComponentsFormatter.maximumUnitCount = 1 dateComponentsFormatter.maximumUnitCount = 1
dateComponentsFormatter.unitsStyle = .full dateComponentsFormatter.unitsStyle = .full
let startEnd = convertTime(facility) let startEnd = getStartEndDates(facility)
if(Utilities.isOpen(facility: facility)) { if(Utilities.isOpen(facility: facility)) {
// Might be a better way of doing this, but for now, this works. // Might be a better way of doing this, but for now, this works.
...@@ -151,14 +173,7 @@ class Utilities: NSObject { ...@@ -151,14 +173,7 @@ class Utilities: NSObject {
// TODO: Function to check for special schedules. // TODO: Function to check for special schedules.
static func isSpecialSchedule(_ facility: Facility) -> Bool { static func isSpecialSchedule(_ facility: Facility) -> Bool {
var isSpecial = false return facility.specialSchedule!.isValid
if (facility.specialSchedule == nil) {
isSpecial = false
}
else {
isSpecial = true
}
return isSpecial
} }
static func isMainSchedule(facility: Facility) -> Bool { static func isMainSchedule(facility: Facility) -> Bool {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment