Questions tagged [swiftdate]

SwiftDate is a 3rd party Swift library to make it easier to work with Dates and TimeZones.

Main features of SwiftDate:

  • Simple math operations with dates! Example: aDate + 2.weeks + 1.hour or (1.year - 2.hours + 16.minutes).fromNow()
  • Easy conversions to and from timezone, locale and calendar. Use the helper class DateInRegion and perform conversions with components and operations!
  • Compare dates with math operators <,>,==,<=,>=. For example, you can do aDate1 >= aDate2 or aDate1.isIn(anotherDate,.day)
  • Easily work with time components. E.g. aDateInRegion.day or hour, minutes etc. expressed in your favourite timezone!
  • Easy and optimized way to get and transform a date from and to strings: supports both colloquial (human readable) and fixed formats (ISO8601, AltRSS, RSS, Extended, .NET and custom string as per Unicode standard)
  • Express time interval in other time units; for example 120.seconds.in(.minutes) // 2 minutes
  • Many shortcuts to get intervals, work with time units, intervals and common date operations (isYesterday,isTomorrow,isBefore()...)

For more information, see the GitHub page of SwiftDate.

24 questions
8
votes
1 answer

Swift Package Manager - Unexpected duplicate tasks: Target AppTests (project App) has copy command - SwiftDate

I'm migrating my project from Carthage to SPM. I'm using Xcode 12.0. Building the main app works without any problems but I cannot run my unit tests anymore. I use the same framework SwiftDate v6.2.0 in both my App target (SPMD) and my App test…
Yannick
  • 3,210
  • 1
  • 21
  • 30
5
votes
1 answer

Using DateFormatter with TimeZone to format dates in Swift

How can I parse a date that has only date information (without time), like 2018-07-24 Im trying with let dateFormatter = DateFormatter() dateFormat.dateFormat = "yyyy-MM-dd" dateFormatter.dateFormat = dateFormat dateFormatter.timeZone =…
Daniel Gomez Rico
  • 15,026
  • 20
  • 92
  • 162
2
votes
2 answers

Swift: Precision with timeIntervalSince1970

When I convert Unix epoch time to milliseconds, it's getting rounded. Code: import Foundation extension Date { public func getMilliSeconds()-> TimeInterval { return TimeInterval(self.timeIntervalSince1970) } } let epochTime:…
user1107173
  • 10,334
  • 16
  • 72
  • 117
2
votes
2 answers

How to print Date&time (localized) in current timezone using SwiftDate framework

I'm using SwiftDate framework (see link below) https://github.com/malcommac/SwiftDate I'd like to print the date and time in current region/local/timeZone. I can achieve this by using the below code without using…
Felix Marianayagam
  • 2,634
  • 2
  • 9
  • 29
2
votes
2 answers

Hours between dates with SwiftDate

What's the easiest way to get number of hours between 2 dates with SwiftDate lib? In this case hours could be days / minutes or whatever I'll need next time. I see I can probably do (date1 - date2) / 60 * 60 but that just does not feel right.
Dannie P
  • 4,464
  • 3
  • 29
  • 48
1
vote
2 answers

SwiftDate 5.0 compilation issues

When I install SwiftDate through Cocoapods and try to build my project, I get three errors from the SwiftDate library: /Pods/SwiftDate/Sources/SwiftDate/DateInRegion/DateInRegion.swift:11:15: Type 'DateInRegion' does not conform to protocol…
Nolan Gelinas
  • 53
  • 1
  • 8
1
vote
1 answer

SwiftDate string parsing returned 1 day less result

I'm trying to parse a date string into a Date class. I'm using SwiftDate for this. But when I tried to parse it, it returned 1 day less than the value in the string. Here are some examples: let birthString = "1996-10-08" self.birthday =…
1
vote
1 answer

Swift string convert to SwiftDate

How can I convert 12 Oct 2018 at 10:45:46 AM to SwiftDate DateInRegion? My code returns nil: let ds = "12 Oct 2018 at 10:45:46 AM" let region = Region(tz: TimeZone.current, cal: CalendarName.gregorian.calendar, …
binsnoel
  • 276
  • 2
  • 17
1
vote
1 answer

Cannot add SwiftCalendar as a dependency in vapor3 project via package manager

I am currently trying to add SwiftDate to a Vapor3 project via the swift package manager. Here is my package file: // swift-tools-version:4.0 import PackageDescription let package = Package( name: "timeshare", dependencies: [ // A…
Jan
  • 907
  • 1
  • 8
  • 23
1
vote
3 answers

SwiftDate and date calculation

I'm trying to calculate the number of weeks and days that a pet is alive. I'm using SwiftDate for that. So I let the user select a birthdate and compare it to the current date. I don't want to compare the time... so both the birthdate and current…
arakweker
  • 1,535
  • 4
  • 18
  • 40
1
vote
2 answers

How to change the timeZone in SwiftDate?

I have displayed the list of timezones in my app. If user selects a particular timezones, I need to change the local timezone to the selected timezone by the user. let region = Region(tz: timeZoneName.timeZone , cal: cal, loc: cal.locale!) let…
sathish
  • 571
  • 1
  • 5
  • 16
1
vote
1 answer

failed to render instance library not loaded [macOS]

I am getting the above error while trying to implement @IBDesignable in my class. I have tried all the online solutions like deleting derived date updating pod etc. But nothing is working for me. I am using cocoapods version 1.2.1 This is how my…
sumesh
  • 2,179
  • 2
  • 21
  • 37
0
votes
1 answer

Swift UI charts & dates

I'm trying to implement a chart in Swift UI based on specific dates for an expenses app. I can get the total amount per month & display each, but I'm stuck on showing payments for a specific month (.i.e last month, current month) split by weeks. I'm…
H121
  • 1
  • 1
0
votes
1 answer

iOS simulator keeps seeing old system calendar type (Gregorian/iso8601)

I changed calendar type from Gregorian to ISO8601 in my MacOS's system preferences but when I launch my app in simulator it always returns gregorian Here's how I check the value: print("Calendar.current.identifier =…
eugene_prg
  • 948
  • 2
  • 12
  • 25
0
votes
1 answer

How to show different views based on date

I need to show a certain view on a certain day, so tried to do it based on date, but it doesn't work, pleas help me to solve this problem ... func UpdateData() { let current = Calendar.current let date =…
Danylo
  • 1
1
2