Skip to content

jiang443/NVDate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Build Status Version

NVDate is library for handling NSDate manipulation in iOS Development.

Features

NVDate have many features that help to solve your problem.

  • Capable to do lot of date manipulation task
  • User friendly naming convention
  • Chainable functions
  • Easy to use
  • Open Source !

Installation

Manually

Download the source, then follow these steps:

  • Objective-C

    Copy both NVDate.h and NVDate.m files into your project

    #import "NVDate.h"
  • Swift

    Copy NVDate.Swift

CocoaPods

Installing NVDate using CocoaPods is easier. Simply add the following line to your Podfile :

pod 'NVDate'

Simple Example

Full date of today

Objective-C
NVDate *date = [[NVDate alloc] initUsingToday];
 
NSLog(@"today is : %@", [date stringValue]);
// today is : Wednesday, February 5, 2014, 4:56:35 PM Western Indonesia Time
Swift
let date = NVDate(isUsingToday: true)

NSLog("today is : %@", date.stringValue());
// today is : Wednesday, February 5, 2014, 4:56:35 PM Western Indonesia Time

Last day of next 2 months

Objective-C
NVDate *date = [[NVDate alloc] initUsingToday];
[date nextMonths:2];
[date lastDayOfMonth];

NSLog(@"next 2 months from today is : %@", [date stringValueWithFormat:@"dd-MM-yyyy"]);
// next 2 months from today is : 30-04-2014
Swift
var date = NVDate(isUsingToday: true)
date.nextMonths(2);
date.lastDayOfMonth(2);

NSLog("next 2 months from today is : %@", date.stringValue(dateFormat: "dd-MM-yyyy"));
// next 2 months from today is : 30-04-2014

Second week of 2 months ago

Objective-C
NVDate *date = [[[[[NVDate alloc] initUsingToday] previousMonths:2] firstDayOfMonth] nextWeek];
date.dateFormatUsingString = @"yyyy-MM-dd HH:mm:ss";

NSLog(@"second week of 2 months ago is : %@", [date stringValue]);
// second week of 2 months ago is : 2013-12-08 17:03:36
Swift
var date = NVDate(isUsingToday: true).previousMonths(2).firstDayOfMonth().nextWeek()
date.dateFormatUsingString = "yyyy-MM-dd HH:mm:ss";

NSLog("second week of 2 months ago is : %@", date.stringValue());
// second week of 2 months ago is : 2013-12-08 17:03:36

Detect if yesterday is friday

Objective-C
BOOL isFriday = [[[[NVDate alloc] initUsingToday] previousDay] isCurrentDayName:NVDayUnitFriday];

NSLog(@"is yesterday was friday ? %@", isFriday ? @"yes" : @"no");
// is yesterday was friday ? no
Swift
Bool isFriday = NVDate(isUsingToday: true).previousDay().isCurrentDayName(.Friday)

NSLog("is yesterday was friday ? %@", isFriday ? "yes" : "no");
// is yesterday was friday ? no

Dot syntax

Objective-C
NVDate *nvDate = [[NVDate alloc] initUsingToday];
NSString someday = nvDate.previousDay.previousWeek.nextDay.stringValue;

NSLog(@"someday %@", someday);
// someday 2013-12-08 17:03:36
Swift
var nvDate = NVDate(isUsingToday: true);
String someday = nvDate.previousDay().previousWeek().nextDay().stringValue();

NSLog(@"someday %@", someday);
// someday 2013-12-08 17:03:36

Documentation

https://github.com/novalagung/NVDate/wiki/API-Reference

Contribution

Feel free to add contribution to this project by fork -> pull request

License

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

About

Easy to use Objc-C NSDate library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 52.3%
  • Swift 44.9%
  • Ruby 2.8%