NVDate is an extension of NSDate class (Swift4), created to make date and time manipulation easier.

Overview

Introduction

Build Status CocoaPods CocoaPods

NVDate is an extension of NSDate class (Swift4), created to make date and time manipulation easier. NVDate is testable and robust, we wrote intensive test to make sure everything is safe.

Features

  • Has lot of API function to make date and time manipulation easier and fun
  • Has user friendly naming convention
  • NVDate functions are chainable
  • Very easy to use
  • Open Source!

Installation

Using Cocoa Pods

Swift4

Add these into your Podfile:

pod 'NVDate', '2.0.1'

Then import NVdate into your swift file.

import NVDate
Objective-C

Add these into your Podfile:

pod 'NVDate', '1.0.0'

Then import NVdate.h into your .h or .m file.

#import "NVDate.h"

Simple Example

Today date as string

let date = NVDate()

print(date.asString())
// ==> Wednesday, February 5, 2014, 4:56:35 PM Western Indonesia Time

Date 2018/05/25 as string

Friday, May 25, 2018, 00:00:00 AM Western Indonesia Time ">
let date = NVDate(fromString: "2018/05/25", withFormat: "yyyy/MM/dd")

print(date.asString())
// ==> Friday, May 25, 2018, 00:00:00 AM Western Indonesia Time

Last day of next 2 months

30-04-2014 ">
let date = NVDate()
    .nextMonths(diff: 2)
    .lastDayOfMonth()

print(date.asString(withFormat: "dd-MM-yyyy"))
// ==> 30-04-2014

Second week of 2 months ago

2013-12-08 17:03:36 ">
let date = NVDate()
    .previousMonths(diff: 2)
    .firstDayOfMonth()
    .nextWeek()
date.dateFormat(setFormat: "yyyy-MM-dd HH:mm:ss")

print(date.asString())
// ==> 2013-12-08 17:03:36

Detect if 2018/05/25 is friday

let todayIsFriday = NVDate(year: 2018, month: 5, day: 25)
    .previousDay()
    .isTodayName(.friday)

print(todayIsFriday)
// ==> false

Dot syntax

let someday = NVDate()
    .previousDay()
    .previousWeek()
    .nextDay()
    .asString()

print(someday)
// ==> 2013-12-08 17:03:36

API Documentation

Initialization

Initialization Description
NVDate() Today date is used as date value
NVDate(fromString:withFormat:) Use specified date string as date value. Format of specified date string has to be explicitly defined.
NVDate(year:month:day:) Construct new date using year, month, and day
NVDate(year:month:day:hour:minute:second:) Construct new date using year, month, day, hour, minute, second
NVDate(fromDate:) use specified date as value

Methods

Method Description
date() return the date object
asString() return string formatted of date object
asString(withFormat:) return formatted string value of date object. the format has to be defined explicitly
setTimeAsZero() set hour, minute, and second as 0
dateFormat() return the current date format. the format is used on asString()
dateFormat(setFormat:) change current date format. the format is used on asString()
dateStyle() return the date style of current formatter
dateStyle(setStyle:) change date style of current formatter
timeStyle() return the time style of current formatter
timeStyle(setStyle:) change time style of current formatter
timeZone() return current timezone value
timeZone(setTimeZone:) change the timezone value
nextDays(days:) move to next x days
nextDay() move to next day
tomorrow() alias of nextDay()
previousDays(days:) move to previous x days
previousDay() move to previous day
yesterday() alias of previousDay()
nextWeek() move to next week
nextWeeks(diff:) move to next x weeks
previousWeek() move to previous week
previousWeeks(diff:) move to previous x weeks
nextMonth() move to next month
nextMonths(diff:) move to next x months
previousMonth() move to previous month
previousMonths(diff:) move to previous x months
nextYear() move to next year
nextYears(diff:) move to next x years
previousYear() move to previous year
previousYears(diff:) move to previous x years
firstDayOfMonth() move to first day of current month
lastDayOfMonth() move to last day of current month
firstMonthOfYear() move to first month of current year
lastMonthOfYear() move to last month of current year
nearestPreviousDay(_:) move to x previous day that name equal to NVDate.DayName
nearestNextDay(_:) move to x next day that name equal to NVDate.DayName
thisDayName() get today day name, in type NVDate.DayName
todayName() alias of thisDayName()
isThisDayName(_:) return true if specified day name is equal with day on the object
isTodayName(_:) alias of isThisDayName(_:)
thisMonthName() get this month name, in type NVDate.MonthName
isThisMonthName(_:) return true if specified month name is equal with month on the object
year() return year value
year(setYear:) change year value
month() return month value
month(setMonth:) change month value
weekOfYear() return week of year value
weekOfMonth() return week of month value
day() return day value
day(setDay:) change day value
hour() return hour value
hour(setHour:) change hour value
minute() return minute value
minute(setMinute:) change minute value
second() return second value
second(setSecond:) change second value

Contribution

Feel free to contribute by doing fork -> pull request

License

http://novalagung.mit-license.org/

You might also like...
Datify 🕛 Easypeasy date functions.

Datify 🕛 Easypeasy date functions.

Intuitive date handling in Swift

Timepiece Intuitive date handling in Swift Features 💡 Intuitive: Timepiece provides a set of helpers to make date handling easier. 🕘 Correct: Using

Elegant NTP date library in Swift
Elegant NTP date library in Swift

Kronos is an NTP client library written in Swift. It supports sub-seconds precision and provides a stable monotonic clock that won't be affected by ch

Swift Date Formatter

Swift Date Formatter Date Formatter - Sample code on how to use Date Formatter in swift language Author: Denow Cleetus For OSSE Assignment 4 Group 24

NasaApod - iOS, Swift, MVVM, Consuming NASA Astronomy Picture of the Day API for any selected date

NasaApod iOS, Swift, MVVM, Unit Tests Consuming NASA Astronomy Picture of the Da

🎗 Super lightweight ISO8601 Date Formatter in Swift
🎗 Super lightweight ISO8601 Date Formatter in Swift

ISO8601 ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut mana

A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.
A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.

TimeZonePicker A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your

Time is a Swift package that makes dealing with calendar values a natural and straight-forward process.

Time Time is a Swift package that makes dealing with calendar values a natural and straight-forward process. Working with calendars can be extremely c

SwiftDate 🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.
SwiftDate 🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.

Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift. What's This? SwiftDate is the definitive toolchain to ma

Comments
  • different dates ?!

    different dates ?!

    NSLog(@"%@, %d, %@", _firstDateOfCalender.date, (int)_firstDateOfCalender.day, [_firstDateOfCalender stringValueWithFormat:@"dd/MM/yyyy"]);

    .date and nvdate.day give different days:

    2014-05-26 22:00:00 +0000, 27, 27/05/2014

    opened by a1exb1 3
  • CocoaPod

    CocoaPod

    Nice library. Have you considered making it a CocoaPod? It's super easy to do (see this PR), and it will help people using in.

    More info here: CocoaPods.org and here.

    Note that you'll need to use semver, I'm happy to explain you how, but that's super easy as well.

    opened by mokagio 3
  • Cannot call value of non-function type 'module<NVDate>'

    Cannot call value of non-function type 'module'

    Hi! Im getting the error above when trying to compile, even with just let date = NVDate() I tried changing from Swift 4 to 4.2 and pod 2.0.1 to 2.1.0.

    opened by AlexanderNorway 0
Owner
Noval Agung Prayogo
Software Architect, Tech Lead, Open Source Enthusiast
Noval Agung Prayogo
SwiftMoment - A time and calendar manipulation library for iOS 9+, macOS 10.11+, tvOS 9+, watchOS 2+ written in Swift 4.

SwiftMoment This framework is inspired by Moment.js. Its objectives are the following: Simplify the manipulation and readability of date and interval

Adrian Kosmaczewski 1.6k Dec 31, 2022
Date Formatter Pool - is a small utility that creates and stores your Date Formatter for simpler reuse

Date Formatter Pool Date Formatter Pool - is a small utility that creates and stores your Date Formatter for simpler reuse Installation is available i

Aleksei Artemev 13 Sep 6, 2022
A basic countdown app that allows the user to create, edit, and delete events. Each event contains a live countdown timer to a specified date and time.

Event Countdown App (iOS) Created by Lucas Ausberger About This Project Created: January 4, 2021 Last Updated: January 8, 2021 Current Verison: 1.1.1

Lucas Ausberger 1 Jan 8, 2022
Date and time manager for iOS/OSX written in Swift

Tempo was designed to work both in OSX and in iOS (7.0+). Work with the time or dates can be cumbersome, iOS development. Tempo allows you to deal easly with date and time. Basics manipulations are already implemented in Tempo.

Remi ROBERT 153 Jun 3, 2021
DateHelper - A high performant Swift Date Extension for creating, converting, comparing, or modifying dates.

DateHelper A high performant Swift Date Extension for creating, converting, comparing, or modifying dates. Capabilities Creating a Date from a String

Melvin Rivera 1.4k Jan 2, 2023
Swifty Date & Time API inspired from Java 8 DateTime API.

AnyDate Swifty Date & Time API inspired from Java 8 DateTime API. Background I think that date & time API should be easy and accurate. Previous dates,

Jungwon An 182 Dec 1, 2022
Building a better date/time library for Swift

Time Time is a Swift package that makes dealing with calendar values a natural and straight-forward process. Working with calendars can be extremely c

Dave DeLong 2k Dec 31, 2022
Swifty Date & Time API inspired from Java 8 DateTime API.

AnyDate Swifty Date & Time API inspired from Java 8 DateTime API. Background I think that date & time API should be easy and accurate. Previous dates,

Jungwon An 182 Dec 1, 2022
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!

Datez ?? Breeze through Date, DateComponents, and TimeInterval Highlights Two Custom Structs Only (value types FTW!): DateView: An Date associated wit

Kitz 263 Dec 7, 2022
A customizable date picker for watchOS and SwiftUI.

Watch Date Picker A customizable date picker for watchOS and SwiftUI. Installation .package(url: "https://github.com/freyaariel/watch-date-picker.git"

Freya Ariel 30 Dec 4, 2022