Giter Site home page Giter Site logo

datehelper's Introduction

DateHelper 5.0.1

License Platform Carthage Compatible Swift Package Manager Compatible

Sample Project Screenshot

A high performant Swift Date Extension for creating, comparing, or modifying dates.

Capabilities

  • Date from String
    • Using date detection i.e. "Tomorrow at 5:30 PM"
    • With predefined format: i.e. .isoDateTime
    • With custom format: i.e. "dd MMM yyyy HH:mm:ss"
  • String from Date
    • With predefined format: i.e. .rss
    • With custom format: i.e. ""MMM d, yyyy""
    • With combined date and time style: i.e. .medium
    • With individual date and time style: i.e. .medium, .short
  • Modify Date
    • Offset date component: i.e. .offset(.second, value: 110)
    • Adjust date component: i.e. .adjust(hour: 12, minute: 0, second: 0)
    • Adjust date to a predefined time: i.e. .adjust(for: .startOfDay)
  • Compare Date
    • Compare against relative date in predefined format: i.e. .isToday, .isThisWeek
    • Compare againnst target date: i.e. firstDate.compare(.isSameMonth(as: secondDate))
  • Time Since
    • Time since target date in component: i.e. Date().since(secondDate, in: .second)
  • Extras
    • Extract date and time components: i.e. .hour, .minute, .day
    • Conveniance methods: i.e. numberOfDaysInMonth(), firstDayOfWeek(), .lastDayOfWeek()

Date From String

Provides initializers to create a Date from a String

Detect a Date from natural language in a String

Date(detectFromString: "Tomorrow at 5:30 PM")

Uses NSDataDetector to detect a date from natural language in a string. It works similar to how Apple Mail detects dates. This initializer is not as efficient as fromString:format: and should not be used in collections or lists.

Date from a string with predefined format

 Date(fromString: "2009", format: .isoYear)
 Date(fromString: "2009-08", format: .isoYearMonth)
 Date(fromString: "2009-08-11", format: .isoDate)
 Date(fromString: "2009-08-11T06:00:00-07:00", format: .isoDateTime)
 Date(fromString: "2009-08-11T06:00:00.000-07:00", format: .isoDateTimeFull)
 Date(fromString: "/Date(1260123281843)/", format: .dotNet)
 Date(fromString: "Fri, 09 Sep 2011 15:26:08 +0200", format: .rss)
 Date(fromString: "09 Sep 2011 15:26:08 +0200", format: .altRSS)
 Date(fromString: "Wed, 01 03 2017 06:43:19 -0500", format: .httpHeader)

Highly performant, cached and thread safe. Can optionally receive timeZone, locale or isLenient flag.

Date from a string with custom format

 Date(fromString: "16 July 1972 6:12:00", format: .custom("dd MMM yyyy HH:mm:ss"))

Highly performant, cached and thread safe. Can optionally receive timeZone, locale or isLenient flag.

String From Date

Provides three ways to convert a Date object to a String

Convert Date to String using predefined format

Date().toString(format: .isoYear)
"2017"
Date().toString(format: .isoYearMonth)
"2017-03"
Date().toString(format: .isoDate)
"2017-03-01"
Date().toString(format: .isoDateTime)
"2017-03-01T06:43:19-05:00"
Date().toString(format: .isoDateTimeFull)
"2017-03-01T06:43:19.000-05:00"
Date().toString(format: .dotNet)
"/Date(-51488368599000.000000)/"
Date().toString(format: .rss)
"Wed, 1 Mar 2017 06:43:19 -0500"
Date().toString(format: .altRSS)
"1 Mar 2017 06:43:19 -0500"
Date().toString(format: .httpHeader)
"Wed, 01 03 2017 06:43:19 -0500"

Highly performant, cached and thread safe. Can optionally receive timeZone and locale.

Convert Date to String using custom format

Date().toString(format: .custom("MMM d, yyyy"))
"Mar 1, 2017"
Date().toString(format: .custom("h:mm a"))
"6:43 AM"
Date().toString(format: .custom("MMM d"))
"Wed Mar 1"

Highly performant, cached and thread safe. Can optionally receive timeZone and locale.

Convert Date to String using predefined combined date and time styles

Date().toString(style: .short) 
"3/1/17, 6:43 AM"
Date().toString(style: .medium)
"Mar 1, 2017 at 6:43:19 AM"
Date().toString(style: .long)
"March 1, 2017 at 6:43:19 AM EST"
Date().toString(style: .full)
"Wednesday, March 1, 2017 at 6:43:19 AM Eastern Standard Time"
Date().toString(style: .ordinalDay)
"1st"
Date().toString(style: .weekday)
"Wednesday"
Date().toString(style: .shortWeekday)
"Wed"
Date().toString(style: .veryShortWeekday)
"W"
Date().toString(style: .month)
"April"
Date().toString(style: .shortMonth)
"Apr"
Date().toString(style: .veryShortMonth)
"A"

Convert Date to String using predefined individual date and time styles

Date().toString(dateStyle: .none, timeStyle: .short)
"6:43 AM"
Date().toString(dateStyle: .short, timeStyle: .none)
"3/1/17"
Date().toString(dateStyle: .short, timeStyle: .short)
"3/1/17, 6:43 AM"
Date().toString(dateStyle: .medium, timeStyle: .medium)
"Mar 1, 2017 at 6:43:19 AM"
Date().toString(dateStyle: .long, timeStyle: .long)
"March 1, 2017 at 6:43:19 AM EST"
Date().toString(dateStyle: .full, timeStyle: .full)
"Wednesday, March 1, 2017 at 6:43:19 AM Eastern Standard Time"

Modifying dates

Provides functions for adjusting or shifting dates

Offset components

Date().offset(.second, value: 10)
"18:14:41" -> "18:14:51"
Date().offset(.minute, value: 10)
"18:14:41" -> "18:24:41"
Date().offset(.hour, value: 2)
"18:14:41" -> "20:14:41"
Date().offset(.day, value: 1)
"2009-12-06" -> "2009-12-07"
Date().offset(.weekday, value: 2)
"2009-12-06" -> "2009-16-06"
Date().offset(.weekdayOrdinal, value: 1)
"2009-12-06" -> "2009-12-20"
Date().offset(.week, value: -2)
"2009-12-06" ->  "2009-11-22"
Date().offset(.month, value: 2)
"2009-12-06" -> "2010-02-06"
Date().offset(.year, value: -2)
"2009-12-06" -> "2007-12-06"

Adjust components

Modifies date with the specified date component

Date().adjust(hour: 1, minute: 10, second: 30, day: 15, month: 1)
"2009-12-06 18:14:41" -> "2009-01-15 06:10:30"
Date().adjust(minute: 59)
"2009-12-06 18:14:41" -> "2009-12-06 18:59:30"

Adjust date

Modifies date with predefined times like endOfDay, startOfDay startOfWeek etc.

Date().adjust(for: .startOfDay)
"2009-12-06 18:14:41" -> "2009-12-06 00:00:00"
Date().adjust(for: .endOfDay)
"2009-12-06 18:14:41" -> "2009-12-06 23-59-59"
Date().adjust(for: .startOfWeek)
"2009-12-08 18:14:41" -> "2009-12-06 18:14:41"
Date().adjust(for: .endOfWeek)
"2009-12-06 18:14:41" -> "2009-12-12 18:14:41"
Date().adjust(for: .startOfMonth)
"2009-12-06 18:14:41" -> "2009-12-01 18:14:41"
Date().adjust(for: .endOfMonth)
"2009-12-06 18:14:41" -> "2009-12-31 18:14:41"
Date().adjust(for: .tomorrow)
"2009-12-06 18:14:41" -> "tomorrow at 18:14:41"
Date().adjust(for: .yesterday)
"2009-12-06 18:14:41" -> "yesterday at 18:14:41"
Date().adjust(for: .nearestMinute(minute:30))
"2009-12-07 18-14-00" -> "2009-12-07 18-00-00"
"2009-12-07 18-40-00" -> "2009-12-07 18-30-00"
"2009-12-07 18-50-00" -> "2009-12-07 19-00-00"
Date().adjust(for: .nearestHour(hour:2)) 
"2009-12-07 18-00-00" -> "2009-12-08 00-00-00"
"2009-12-07 07-00-00" -> "2009-12-07 12-00-00"
"2009-12-07 03-00-00" -> "2009-12-07 00-00-00"
Date().adjust(for: .startOfYear)
"2009-12-06 18:14:41" -> "2009-01-01 00-00-00"
Date().adjust(for: .endOfYear)
"2009-12-06 18:14:41" -> "2009-12-31 23-59-59"

Compare Dates

Compares dates using predefined times like today, tomorrow, this year, next year etc. Returns true if it matches.

Compare against relative date

Date().compare(.isToday)
Date().compare(.isTomorrow)
Date().compare(.isYesterday)
Date().compare(.isThisWeek)
Date().compare(.isNextWeek)
Date().compare(.isLastWeek)
Date().compare(.isThisYear)
Date().compare(.isNextYear)
Date().compare(.isLastYear)
Date().compare(.isInTheFuture)
Date().compare(.isInThePast)
Date().compare(.isWeekend)
"2021-12-15" != weekend
"2021-12-18" == weekend

Compare against another date

firstDate.compare(.isSameDay(as: secondDate))
"2022-01-08" != "2022-01-07"
"2022-01-06" != "2022-01-07"
"2022-01-07" == "2022-01-07"
firstDate.compare(.isSameWeek(as: secondDate))
"2022-01-14" != "2022-01-07"
"2021-12-31" != "2022-01-07"
"2022-01-07" == "2022-01-07"
firstDate.compare(.isSameMonth(as: secondDate))
"2022-02-07" != "2022-01-07"
"2021-12-07" != "2022-01-07"
"2022-01-07" == "2022-01-07"
firstDate.compare(.isSameYear(as: secondDate))
"2023-01-07" != "2022-01-07"
"2021-01-07" != "2022-01-07"
"2022-01-07" == "2022-01-07"
firstDate.compare(.isEarlier(than: secondDate))
"2022-01-07 19:26:53" != "2022-01-07 19:25:53"
"2022-01-07 19:24:53" == "2022-01-07 19:25:53"
firstDate.compare(.isLater(than: secondDate))
"2022-01-07 19:28:49" == "2022-01-07 19:27:49"
"2022-01-07 19:26:49" != "2022-01-07 19:27:49"

Time since...

Returns a number in the specified unit of measure since the secondary date.

Date().since(secondDate, in: .second)
"2009-12-06 06-14-11" since "2009-12-06 06-13-41" in .second == 30 
Date().since(secondDate, in: .minute)
"2009-12-06 06-14-11" since "2009-12-06 04-14-11" in .minute == 120 
Date().since(secondDate, in: .hour)
"2009-12-06 06-14-11" since "2009-12-06 04-14-11" in .hour == 2 
Date().since(secondDate, in: .day)
"2009-12-06" since "2009-12-05" in .day == 1 
Date().since(secondDate, in: .week)
"2009-12-06" since "2009-11-29" in .week == 1
"2009-12-06" since "2009-12-13" in .week == -1
Date().since(secondDate, in: .weekdayOrdinal)
"2009-12-06" since "2009-11-22" in .weekdayOrdinal == 2
Date().since(secondDate, in: .month)
"2009-12-06" since "2009-11-06" in .month == 2
Date().since(secondDate, in: .year)  
"2009-12-06" since "2008-12-06" in .year == 1

Miscellaneous

Extracting components from a date

Date().component(.second)
"2009-12-06 18:14:11" .second == "11"
Date().component(.minute)
"2009-12-06 18:14:11" .minute == "14"
Date().component(.hour)
"2009-12-06 18:14:11" .hour == "18"
Date().component(.day)
"2009-12-06 18:14:11" .day == "6"
Date().component(.weekday)
"2009-12-06 18:14:11" .weekday == "1"
Date().component(.weekdayOrdinal)
"2009-12-06 18:14:11" .weekdayOrdinal == "1"
Date().component(.month)
"2009-12-06 18:14:11" .month == "12"
Date().component(.year)
"2009-12-06 18:14:11" .year == "2009"

Conveneience methods

Date().numberOfDaysInMonth()
"2021-12-17" numberOfDaysInMonth() == 31
Date().firstDayOfWeek()
"2021-12-17" firstDayOfWeek() == 12
Date().lastDayOfWeek()
"2021-12-17" lastDayOfWeek() == 19

Custom start day of the week

var calendar = Calendar(identifier: .gregorian)
calendar.firstWeekday = 2 // sets the week to start on Monday
Date().dateFor(.startOfWeek, calendar: calendar)

Custom Component guide

Unicode Date Field Symbol Guide

Format Description Example
"y" 1 digit min year 1, 42, 2017
"yy" 2 digit year 01, 42, 17
"yyy" 3 digit min year 001, 042, 2017
"yyyy" 4 digit min year 0001, 0042, 2017
"M" 1 digit min month 7, 12
"MM" 2 digit month 07, 12
"MMM" 3 letter month abbr. Jul, Dec
"MMMM" Full month July, December
"MMMMM" 1 letter month abbr. J, D
"d" 1 digit min day 4, 25
"dd" 2 digit day 04, 25
"E", "EE", "EEE" 3 letter day name abbr. Wed, Thu
"EEEE" full day name Wednesday, Thursday
"EEEEE" 1 letter day name abbr. W, T
"EEEEEE" 2 letter day name abbr. We, Th
"a" Period of day AM, PM
"h" AM/PM 1 digit min hour 5, 7
"hh" AM/PM 2 digit hour 05, 07
"H" 24 hr 1 digit min hour 17, 7
"HH" 24 hr 2 digit hour 17, 07
"m" 1 digit min minute 1, 40
"mm" 2 digit minute 01, 40
"s" 1 digit min second 1, 40
"ss" 2 digit second 01, 40
"S" 10th's place of fractional second 123ms -> 1, 7ms -> 0
"SS" 10th's & 100th's place of fractional second 123ms -> 12, 7ms -> 00
"SSS" 10th's & 100th's & 1,000's place of fractional second 123ms -> 123, 7ms -> 007

Requirements

Language: Swift 5.0 Supports: iOS, tvOS, watchOS, macOS

Installation

Swift Package Manager https://github.com/melvitax/DateHelper.git
Carthage github "melvitax/DateHelper"
Manually Include DateHelper.swift in your project

Author

Melvin Rivera

License

DateHelper is available under the MIT license. See the LICENSE file for more info.

datehelper's People

Contributors

abuobaida avatar acrookston avatar adambco avatar aenglund avatar alex-knyaz avatar alfredcc avatar anuragalla avatar astralize avatar cooloneofficial avatar danjiang5956 avatar igrandav avatar imrabti avatar iranjith4 avatar liusky avatar logankriete avatar lucasmpaim avatar melvitax avatar merlin910 avatar neifmetus avatar paoloandrea avatar patricks avatar pec1985 avatar pixel16 avatar sahandnayebaziz avatar sauvikatinnofied avatar tthbalazs avatar vittoriom avatar xavi-matos avatar yyjim avatar ziogaschr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

datehelper's Issues

Int overflow for dates far in the future

secondsAfterDate casts the timeIntervalSinceDate result into an Int32 and not an Int64, so results for dates that are far in the future (i.e. 2100-01-01 00:00:00) will overflow 32 bits and cause a crash.

This probably applies to other methods that are implemented similarly to secondsAfterDate.

Use pod_target_xcconfig instead of xcconfig in the podspec or remove it

Could you please remove s.xcconfig from your podspec or replace it with pod_target_xcconfig?

Using xcconfig in your podspec will lead cocoapods to set SWIFT_VERSION to 3.1 for the project target on pod install, which is wrong if using Xcode 9 / Swift 4. The only workaround is to overwrite the SWIFT_VERSION in the project traget, which in turn will cause cocoapods to complain about the target overriding the SWIFT_VERSION setting.

See CocoaPods/issues/5952 for reference.

Month addition and substraction

How about adding these?

date.dateByAddingMonths(2) -> NSDate
date.dateBySubtractingMonths(4) -> NSDate

On the same grounds

date.dateByAddingWeeks(2) -> NSDate
date.dateBySubtractingWeeks(4) -> NSDate

error with ExSwift

when AFDateHelper used with ExSwift (https://github.com/pNre/ExSwift), will raise an error

AFDateHelper/AF+Date+Helper/AF+Date+Extension.swift:27:263: Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

thanks

Day Suffix

Might be nice to add a day suffix to the library. Something like:

`extension Date {

static func getSuffix(forDate date: Date) -> String {
    if let day = date.component(.day) {
        let st: Set = [1, 21, 31]
        let nd: Set = [2, 22]
        let rd: Set = [3, 23]
        if st.contains(day) {
            return "st"
        }
        else if nd.contains(day) {
            return "nd"
        }
        else if rd.contains(day) {
            return "rd"
        }
        else {
            return "th"
        }
    } else {
        return ""
    }
}

}`

Thanks!

ISO8601 format currently doesn't work with milliseconds

Just a heads up that ISO8601 formatted dates with milliseconds aren't currently supported. Pretty easy to add:

let ISO8601Format = "yyyy-MM-dd'T'HH:mm:ssZ"
let ISO8601FormatWithMilliseconds = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"

Easy enough to just try the second formatter if the first one fails.

Caching of formatter doesn't work

        let locale = Locale(identifier: "en_US_POSIX")

        let str = "2017-07-19T14:32:20.000+03:00"

        let format = "yyyy-MM-dd\'T\'HH:mm:ss.SSSZ"

        let d1 = Date(fromString: str, format: .custom(format), locale: locale)

        let d2 = Date(fromString: str, format: .custom(format), locale: locale)

        print(d1)
        print(d2)

Put the breakpoint at cachedFormatter, it always tries to create a new formatter and cached formatters is always empty

Validate if the string is correct format

Using NSDate.dateFromString allows me to know if my string matches the format. If it doesn't, I get a nil.

With your extension, it should have a way to validate if my string matches a specific format. If it doesn't, give me nil. Right now, it init the date with self.init() giving me today's date...

My goal would be to try out multiple format and return a date once my format is matched. My format can be more than ISO8601 (MVC, RSS, Custom, etc)

Support for tvOS

With the new Apple TV, the support for tvOS would be great. :)

Not adding time correctly

I liked these extensions but there is one fairly major issue. I believe this is what is referenced in one of the other listed issues.

When adding time to a specific date, you should be using the dateByAddingComponents:toDate:options: function on the NSCalendar class. Otherwise, by just adding seconds it will not function properly across changes in daylight savings, leap years, and potentially other scenarios.

This should be used in all your dateByAdding... functions.

For example, below is the proper way to add one day to the current date in Objective-C.

+ (NSDate *)addDays:(NSInteger)days ToDate:(NSDate *)date
{
    NSCalendar *currentCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

    NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
    dateComponents.day = days;

    return [currentCalendar dateByAddingComponents:dateComponents toDate:date options:0];
}

Hope this is clear.

No such module 'AFDateHelper'

I am using AFDateHelper using cocoa pods in my swift project and i am importing it like this

import AFDateHelper
but getting the "No such module 'AFDateHelper'" error.

`dateAtEndOfWeek()` NOT WORKING

dateAtEndOfWeek() returning same as dateAtStartOfWeek()

println(NSDate().dateAtStartOfWeek())
println(NSDate().dateAtEndOfWeek())

giving me log as the following

2015-08-01 18:30:00 +0000
2015-08-01 18:30:00 +0000

No scheme for Mac setup

Hi, I'm trying to build your library with Carthage for Mac (not iOS). Unfortunately there is no scheme set up for Mac.

Error:

Dependency "DateHelper" has no shared framework schemes for any of the platforms: Mac

toString(.shortMonth) doesn't work properly

In DateHelper.swift
func toString(style:DateStyleType = .short) -> String

has a issue.

    case .month:
        let monthSymbols = Date.cachedFormatter().monthSymbols!
        return monthSymbols[component(.**weekday**)!-1] as String **_// should be month_**
    case .shortMonth:
        let shortMonthSymbols = Date.cachedFormatter().shortMonthSymbols!
        return shortMonthSymbols[component(.**weekday**)!-1] as String **_// should be month_**
    case .veryShortMonth:
        let veryShortMonthSymbols = Date.cachedFormatter().veryShortMonthSymbols!
        return veryShortMonthSymbols[component(.**weekday**)!-1] as String **_// should be month_**

Seconds

What do you have against seconds (joking :P)

It will be nice to include date calculation with seconds (dateByAdding, dateBySubstracting, sedondsSince, etc.)

Thanks!!

an nsformatter is created for each toString() call

by looking at your code, i see that you create a new NSDateFormatter every time toString() is called on a date object.

NSDateFormatters are very expensive to create. see apple's NSDateFormatter's guide in the section titled Cache Formatters for Efficiency.

Hence i think you should create a class-wide instance or a dictionary that associates formatters with keys (if multiple are required).

thanks for the class though! super helpful!

Can we have startOfYear and endOfYear options DateForType?

right now, we can get a date object for the following options:

public enum DateForType {
    case startOfDay, endOfDay, startOfWeek, endOfWeek, startOfMonth, endOfMonth, tomorrow, yesterday, nearestMinute(minute:Int), nearestHour(hour:Int)
}

Can we have additional options like:

startOfYear and endOfYear.

Usage example:

let date = Date()
let df = DateFormatter()
df.dateFormat = "yyyy-MM-dd"
let fromDate: String = df.string(from: date.dateFor(.startOfYear))
let toDate: String = df.string(from: date.dateFor(.endOfYear))

dateWith function is causing creating incorrect dates

Today is 28 Feb 2017. If I write a simple line

   `let startDate = Date().dateFor(.startOfDay)
    
    let endDate = Date().dateFor(.endOfDay)
    
    print(startDate.toString(style: .full) + " to " + endDate.toString(style: .full))`

The result I get is

Friday, February 3, 2017 at 12:00:00 AM Eastern Standard Time to Friday, February 3, 2017 at 11:59:29 PM Eastern Standard Time

This shouldn't be the 3rd of Feb but the 28th.

It looks like in your function dateWith... you're assigning a weekday component to a day component. If you match day = day, the correct date appears. I don't know what else this will break things elsewhere tho.

func dateWith(hour: Int?, minute: Int?, second: Int?, day: Int? = nil, month: Int? = nil) -> Date { var comp = Date.components(self) comp.month = month ?? comp.month comp.day = day ?? comp.weekday comp.hour = hour ?? comp.hour comp.minute = minute ?? comp.minute comp.second = second ?? comp.second return Calendar.current.date(from: comp)! }

Redundant Info.plist file

When installing using pods workspace contains redundant Info.plist file in pod root folder. This blocks uploading build to AppStore (while simulator is still able to run app)

Support for iOS8.0

Your pod file limits support to iOS8.4+, but lots of projects still need to support iOS8.0+

Ive had to copy you DateHelper file to my project rather than using CocoaPods, but it'd be really easy for you to change the Podfile to support iOS8.0

There are a number of forks that have done this, so Im not alone here
Cheers

Use pod_target_xcconfig instead of xcconfig in the podspec

Hi there,

First of all, thanks for this awesome library. :)

After adding it to my project via CocoaPods, I noticed some warnings for both Debug and Release configs:

[!] The `MyProject [Debug]` target overrides the `SWIFT_VERSION` build setting defined in `Pods/Target Support Files/Pods-MyProject/Pods-MyProject.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `MyProject [Release]` target overrides the `SWIFT_VERSION` build setting defined in `Pods/Target Support Files/Pods-MyProject/Pods-MyProject.release.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

Googling led me to CP's Github page that detailed the issue. The advice they gave was to file an issue with the Pod suggesting the usage of pod_target_xcconfig instead of xcconfig in the podspec.

Here's a detailed report made by one of CP's maintainers.

Thanks.

Date incorrect when raw

Hi,
I have saved a date yesterday and it reads -- 2018-04-11 21:09:27 +0000

Though today I printed todays date which should be 2018-04-12 21:09:27 +0000
reads โ†’ 2018-04-11 21:59:18 +0000

This is fixed when I print it to a string but it is not correct when working with the raw" Date".
I'm trying to compare the date I saved yesterday to today and it returns it is the same day.

Thanks in advance for your help.

Bug in pull request

In Pull request 32, #32

"com.allforces.$(PRODUCT_NAME:rfc1034identifier)" was changed to com.allforces.AFDateHelperDemo;

This causes the App Store to reject the ipa when uploading due to the bundle version being invalid

Xcode 10, Apple Watch (arm64_32) minimum deployment

This bundle is invalid. Applications built for more than one architecture require an iOS Deployment Target of 3.0 or later.

You have to set the deployment target for all watchOS targets (although it says iOS) to 3.0 or higher..

By upload to App Store Connect we have one error to minimumOS deployment. It's ok after editing your info.plist file (Carthage build watchOS) to 3.0.

when day is Sunday, isThisWeek() or isNextWeek() both can be true or false

e.g:
date = 10,7,2016 (is Sunday), date.isThisWeek() sometimes return true, sometimes return false, also date.isNextWeek() sometimes return true, sometimes return false. I call this in tableView scroll will change. I print my log as follows: (in China, UTC+8, see 2016-07-09)
------2016-08-28 09:41:36 +0000, thisWeek:false, nextWeek:false
------2016-07-09 16:00:00 +0000, thisWeek:true, nextWeek:false
------2016-07-29 16:00:00 +0000, thisWeek:false, nextWeek:false
------2016-08-28 09:41:36 +0000, thisWeek:false, nextWeek:false
------2016-08-28 09:41:36 +0000, thisWeek:false, nextWeek:false
------2016-07-29 16:00:00 +0000, thisWeek:false, nextWeek:false
------2016-07-09 16:00:00 +0000, thisWeek:false, nextWeek:true
------2016-08-28 09:41:36 +0000, thisWeek:false, nextWeek:false

Start of week on Monday instead of Sunday

I'd like to call dateFor(.startOfWeek) and get Monday's date instead of Sunday's. Same thing with .endOfWeek - Sunday instead of Saturday.
Is there any way to configure this library this way or is it completely dependent on phone settings or something?

Error 'range(at:)' has been renamed to 'rangeAt(_:)'

I get this error every time I update pods
line 34 in DateHelper.swift
.../Pods/AFDateHelper/Sources/DateHelper.swift:34:77: 'range(at:)' has been renamed to 'rangeAt(_:)'

let dateString = (string as NSString).substring(with: match.range(at: 1))
Update to
let dateString = (string as NSString).substring(with: match.rangeAt(1))
then it is ok...

.endOfWeek does not handler a calendar with firstWeekDay set to anything other than default

Looking at dateHelper.siwft lines 367 - 370:

case .startOfWeek: return calendar.date(from: calendar.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self))!

case .endOfWeek: let offset = 7 - component(.weekday)!

note: "case .endOfWeek:" does not include the value of calendar

Consider replacing line 370 with:

return calendar.date(from: calendar.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self))!.adjust(.day, offset: 6)

Cocoapods support

Hi, I tried to find the library from cocoapods.org search engine, but no success.

Is there any missing step, like push a release?

Calculation is not correct

The code does calculation with a hard defined day (24 hours). This isn't the correct way to do date and time calculation because there is daylight savings time in some regions.

Incorrect ISO date with timezones for dates that are too old

let d = Date(fromString:  "1500-01-01", format: .isoDate, timeZone: .utc)
d.toString(format: .isoDateTimeSec)

Output: 1499-12-31T16:07:02-075258

This is not a valid ISO date.

This gives me a valid ISO date

let d = Date(fromString:  "1500-01-01", format: .isoDate, timeZone: .utc)
let f2 = ISO8601DateFormatter()
f2.string(from: d)

Output: 1500-01-01T00:00:00Z

Swift3?

Can we expect swift 3 migration?

Converting to a date a little too forgiving.

I would like to display a message to my users if they enter an invalid date. I am using the standard American date format of MM/dd/yyyy. If the user enters an invalid date such as 14/16/2018 I would like to generate an Invalid Date error message, however, the library currently will convert this to 02/16/2019 - subtracts 12 months from the month and adds them to the year (12 months = 1 year).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.