• Stars
    star
    174
  • Rank 219,104 (Top 5 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ“… Swift4 Date extension library

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

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

let date = NVDate()
    .nextMonths(diff: 2)
    .lastDayOfMonth()

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

Second week of 2 months ago

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/

More Repositories

1

dasarpemrogramangolang

πŸ“– Source Code Website/Ebook Dasar Pemrograman Golang
Go
2,305
star
2

gubrak

βš™οΈ Golang functional utility library with syntactic sugar. It's like lodash, but for Go
Go
481
star
3

dasarpemrogramangolang-example

πŸ“– Source Code Praktik E-book Dasar Pemrograman Golang
Go
325
star
4

dasarpemrogramanrust

πŸ“– Source Code Website/Ebook Dasar Pemrograman Rust
Rust
283
star
5

muslimboard

πŸ•Œ Muslim Board Browser Extension
JavaScript
144
star
6

httpsproxy2http

🚴 Quick HTTPS forward/reverse proxy for your HTTP web service
HTML
120
star
7

dasarpemrogramanpython

πŸ“– Source Code Website/Ebook Dasar Pemrograman Python
Python
53
star
8

golpal

Golpal - Easy to use Golang Eval Library
Go
45
star
9

go-eek

Blazingly fast and safe Go evaluation library, created on top of Go pkg/plugin package
Go
38
star
10

gorep

Simple tools to replace imported package name in golang project
Go
27
star
11

godong

Easiest dynamic http route handler for golang
Go
23
star
12

skeetoverflow

πŸ“‹ A fun browser extension for replacing all reputations on StackOverflow into a percentage of Jon Skeet's point
JavaScript
20
star
13

dasarpemrogramanrust-example

πŸ“– Source Code Praktik E-book Dasar Pemrograman Rust
Rust
19
star
14

learndevops

πŸ“– Source Code E-book Learn Devops
Go
18
star
15

react-native-ble-read-peripheral

Example of Peripheral Communication with React Native BLE (Bluetooth Low Energy)
JavaScript
10
star
16

go-ternary

Ternary helper for Go programming language
Go
9
star
17

dasarpemrogramanpython-example

πŸ“– Source Code Praktik E-book Dasar Pemrograman Python
Python
8
star
18

howto

JavaScript
5
star
19

natskeepalivesubscribe

Example of nats keep-alive subscription in Go
Go
5
star
20

novalagung

4
star
21

mypullrequests

List of my contributions to some open source projects
4
star
22

golang-docker-private-modules-https

Golang Dockerfile with private dependencies, without using ssh (onlyΒ HTTPS)
Dockerfile
4
star
23

aws-cloudflare-ip-whitelist

Rust
3
star
24

my-book

JavaScript
3
star
25

gitbook-plugin-docsearch-v3

DocSearch v3 plugin for HonKit / GitBook legacy
JavaScript
2
star
26

wow-addons-manager

World of Warcraft Addons Manager
1
star
27

mywowmacros

World of Warcraft macros backup
Lua
1
star
28

go-latest-from-source

Go binary built from latest Go source code
Dockerfile
1
star