• Stars
    star
    707
  • Rank 64,036 (Top 2 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 6 years ago

Reviews

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

Repository Details

Parsing, validating, manipulating, and formatting dates easily in Objective-C (API inspired by moment.js)

YLMoment

License Supported Platforms Version Build Status codecov

🕐 YLMoment is a library which provides an high abstraction level for parsing, validating, manipulating, and formatting the dates in Objective-C.

Its API is inspired by the well known moment.js library, however unlike its counterpart, its core is built upon the Foundation Framework components (NSDate, NSCalendar, etc.) to enable the interoperability with them.

This library is designed to facilitate the manipulation of times, dates, calendars, and durations in Objective-C by providing a single, easy, and unified approach to dealing with them.

Getting StartedUsageInstallationContributionContactLicense

Getting Started

If you want have a quick overview of the project take a look to this blog post.

Usage

Formatting Dates

YLMoment *moment = [YLMoment now];

NSLog(@"%@", [moment format:@"MMMM dd yyyy, h:mm:ss a"]); // October 27 2013, 10:49:48 AM
NSLog(@"%@", [moment format:@"MMM dd yy"]);               // Oct 27 13
NSLog(@"%@", [moment format:@"yyyy 'escaped' yyyy"]);     // 2013 escaped 2013
NSLog(@"%@", [moment format]);                            // 2013-10-27T10:49:48+0100

Relative Times

YLMoment *moment1 = [YLMoment momentWithDateAsString:@"20111031"];
NSLog(@"%@", [moment1 fromNow]); // 2 years ago

YLMoment *moment2 = [YLMoment momentWithDateAsString:@"2012/06/20" format:@"yyyy/MM/dd"];
NSLog(@"%@", [moment2 fromNow]); // a year ago

NSLog(@"%@", [[[YLMoment now] startOf:@"day"] fromNow]);  // 19 hours ago
NSLog(@"%@", [[[YLMoment now] endOf:@"day"] fromNow]);    // in 5 hours
NSLog(@"%@", [[[YLMoment now] startOf:@"hour"] fromNow]); // 11 minutes ago

Time Zones

// Uses my current time zone: here the CET time (GMT+1)
YLMoment *now = [YLMoment now];
NSLog(@"%@", [now format]); // 2014-01-18T18:51:10+0100

// Change the time zone of the moment
now.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
NSLog(@"%@", [now format]); // 2014-01-18T17:51:10+0000

// Convenient way to use get the UTC time
YLMoment *utc = [YLMoment utc];
NSLog(@"%@", [utc format]); // 2014-01-18T17:51:10+0000

Languages

YLMoment supports a lot of languages (see the list below) and is easy to use.

YLMoment *french = [[YLMoment now] addAmountOfTime:-3 forUnitKey:@"s"];
[french setLocale:[NSLocale localeWithLocaleIdentifier:@"fr_FR"]];
NSLog(@"%@", [french fromNow]); // il y a quelques secondes

YLMoment *albanian = [[YLMoment now] addAmountOfTime:-3 forUnitKey:@"s"];
[albanian setLocale:[NSLocale localeWithLocaleIdentifier:@"sq_AL"]];
NSLog(@"%@", [albanian fromNow]); // disa sekonda me parë

YLMoment *spanish = [[YLMoment now] subtractAmountOfTime:3 forUnitKey:@"s"];
[spanish setLocale:[NSLocale localeWithLocaleIdentifier:@"es_ES"]];
NSLog(@"%@", [spanish fromNow]); // hace unos segundos

YLMoment *reference = [YLMoment momentWithArray:@[@2013]];
YLMoment *english   = [[YLMoment now] subtractAmountOfTime:3 forUnitKey:@"s"];
[english setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US"]];
NSLog(@"%@", [english fromMoment:reference]); // in 11 months

Supported languages

Here the list of supported languages:

  • Albanian
  • Chinese
  • Dutch
  • English
  • French
  • German
  • Italian
  • Japanese
  • Portuguese
  • Spanish
  • Vietnamese

All contribution is welcomed! ;)

Installation

The recommended approach to use YLMoment in your project is using the CocoaPods package manager, as it provides flexible dependency management and dead simple installation.

CocoaPods

Install CocoaPods if not already available:

$ [sudo] gem install cocoapods
$ pod setup

Go to the directory of your Xcode project, and Create and Edit your Podfile and add YLMoment:

$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '5.0'
# Or platform :osx, '10.8'
pod 'YLMoment', '~> 0.9.1'

Install into your project:

$ pod install

Open your project in Xcode from the .xcworkspace file (not the usual project file)

$ open MyProject.xcworkspace

Manually

Download the project and copy the YLMoment folder into your project and then simply #import "YLMoment.h" in the file(s) you would like to use it in.

Contribution

Contributions are welcomed and encouraged .

Contact

Yannick Loriot

License (MIT)

Copyright (c) 2013-present - Yannick Loriot

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

DynamicColor

Yet another extension to manipulate colors easily in Swift and SwiftUI
Swift
3,030
star
2

QRCodeReader.swift

Simple QRCode reader in Swift
Swift
1,328
star
3

YLProgressBar

UIProgressView replacement with an highly and fully customizable animated progress bar in pure Core Graphics
Objective-C
1,277
star
4

DynamicButton

Yet another animated flat buttons in Swift
Swift
1,170
star
5

Splitflap

A simple split-flap display for your Swift applications
Swift
1,081
star
6

FlowingMenu

Interactive view transition to display menus with flowing and bouncing effects in Swift
Swift
974
star
7

AwaitKit

The ES8 Async/Await control flow for Swift
Swift
750
star
8

QRCodeReaderViewController

Simple QRCode reader for iOS 7 and over
Objective-C
628
star
9

Reactions

Fully customizable Facebook reactions like control
Swift
584
star
10

SnappingStepper

An elegant alternative to the UIStepper written in Swift
Swift
428
star
11

Perspective

Powerful scrolling and motion parallax for iOS
Swift
268
star
12

CCControlExtension

Collection of classes to make the design of controls easier for Cocos2d-for-iPhone
Objective-C
208
star
13

Box2D-Examples

Box2D examples (Ragdoll, Buoyancy, etc.) for Cocos2D for iPhone
Objective-C
70
star
14

Petal

Beautiful activity indicator to show that a task is in progress
Swift
67
star
15

YLFlowingMenu

The Objective-C counterpart of FlowingMenu
Objective-C
28
star
16

YLTCPBroadcaster

Fast and easy-to-use network scanner to locate every host with a given open port
Objective-C
18
star
17

DynamicFont

Yet another extension to manipulate fonts easily in Swift
Swift
8
star
18

VLCRemoteKit

Remote control for VLC using the HTTP interface in Swift (Under Development)
Swift
3
star
19

Cocarde

Under development
Swift
1
star
20

RSSReaderDemonstrationApp

RSS Reader application for education purpose
Objective-C
1
star