Skip to content
/ Day Public

Mini library to represent a Day value with serialization functionality.

License

Notifications You must be signed in to change notification settings

numen31337/Day

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Day

Platform CocoaPods Build Status

Day is the mini library to represent a Day value with serialization functionality. Mainly for private use.

Features

  • Can be created from the Date with resetting of its time components
  • Serialization to the human-readable and sortable String and back
  • Caching (for internal usage)
  • Day seeking algorithms (primarily for my personal need)
  • Convenient property for accessing next and previous day
  • Day offset calculations

Usage

Initialising:

let day = Day() //Day value for the current day
let day = Day(date) //Day value from the date by dropping time components

Serialization:

let serializedString = day.serializedDayString //A serialized string value
let day = Day(serializedString) //Day value from the serialized string

Getting a Date value from the Day value:

let date = day.rawValue

Day calculations:

let nextDay = day.nextDay
let previousDay = day.prevDay
let twoDaysBefore = day.dayBy(addingDays: -2)

Difference between two days:

let diff = day.numberOfDays(sinceDay: day1)
let diff = day.numberOfDays(toDate: day1)