All Projects → sshaw → Yymmdd

sshaw / Yymmdd

Tiny DSL for idiomatic date parsing and formatting in Ruby

Programming Languages

ruby
36898 projects - #4 most used programming language
dsl
153 projects
metaprogramming
66 projects

Labels

Projects that are alternatives of or similar to Yymmdd

Protodate
Better Javascript Dates.
Stars: ✭ 14 (-81.82%)
Mutual labels:  date
Persianrangedatepicker
Persian range date picker for android.
Stars: ✭ 48 (-37.66%)
Mutual labels:  date
Xfce4 Genmon Scripts
🐭 XFCE panel generic monitor scripts
Stars: ✭ 69 (-10.39%)
Mutual labels:  date
React Picky Date Time
A react component for date time picker. Online demo examples
Stars: ✭ 31 (-59.74%)
Mutual labels:  date
Period
Complex period comparisons
Stars: ✭ 1,001 (+1200%)
Mutual labels:  date
Pgo
Go library for PHP community with convenient functions
Stars: ✭ 51 (-33.77%)
Mutual labels:  date
Date Info
API to let user fetch the events that happen(ed) on a specific date
Stars: ✭ 7 (-90.91%)
Mutual labels:  date
Android Pickerdialog
一个兼容手机和电视(焦点选择)的高仿IOS风格的选择器
Stars: ✭ 72 (-6.49%)
Mutual labels:  date
Pickadate.js
The mobile-friendly, responsive, and lightweight jQuery date & time input picker.
Stars: ✭ 7,753 (+9968.83%)
Mutual labels:  date
When
A natural language date/time parser with pluggable rules
Stars: ✭ 1,113 (+1345.45%)
Mutual labels:  date
Date2name
Handling time-stamps and date-stamps in file names
Stars: ✭ 37 (-51.95%)
Mutual labels:  date
Mnth
📆 Calendar month as 2d array of Dates
Stars: ✭ 41 (-46.75%)
Mutual labels:  date
Zulu
A drop-in replacement for native Python datetimes that embraces UTC.
Stars: ✭ 52 (-32.47%)
Mutual labels:  date
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+48436.36%)
Mutual labels:  date
Iso8601
Ruby parser to work with ISO8601 dateTimes and durations — http://en.wikipedia.org/wiki/ISO_8601
Stars: ✭ 70 (-9.09%)
Mutual labels:  date
Rsdayflow
iOS 7+ Calendar (Date Picker) with Infinite Scrolling.
Stars: ✭ 843 (+994.81%)
Mutual labels:  date
Intl Date Time
International DateTime for Laravel Nova
Stars: ✭ 50 (-35.06%)
Mutual labels:  date
Carbon
A simple PHP API extension for DateTime
Stars: ✭ 75 (-2.6%)
Mutual labels:  date
Dategrid
A customizable swiftui calendar
Stars: ✭ 71 (-7.79%)
Mutual labels:  date
Laydate
layDate(日期与时间组件) 是 layui 独立维护的三大组件之一
Stars: ✭ 1,066 (+1284.42%)
Mutual labels:  date

YYMMDD

Build Status

Tiny DSL for idiomatic date parsing and formatting.

Overview

require "yymmdd"

include YYMMDD

puts yy/mm              # 14/08 (i.e., today's date)
puts yyyy/mm            # 2014/08
date = ymd(411207)      # Date.new(1941, 12, 7)

date = Date.today
puts yyyy.mm.dd(date)   # 2014.08.09
puts dd/mm/yy(date)     # 08/09/14
puts ymd(date)          # 1489
puts yymmdd(date)       # 140809

date = yyyy.mm.dd("1941.12.07")  # Date.new(1941, 12, 7)
date = mm.dd.yy("11.22.63")      # Date.new(1963, 11, 22)
date = mm/dd/yy("11/21/99")      # ...
date = mm/dd/yyyy("11/21/1999")
date = mm-dd-yyyy("11-21-1999")
date = m-d-y("11-21-99")

Installation

Rubygems:

gem install yymmdd

Bundler:

gem "yymmdd"

Usage

All functions are module_functions so you must include YYMMDD to use them.

When given a String it will attempt to parse it as the specified format and return a Date.

When given a Date it will return a String in the specified format.

An ArgumentError is raised if the date can't be parsed or formatted.

With no arguments it will return an instance of a String-like object (it overrides to_s and to_str) representing today's date in the specified format. In the most common cases you can treat it like a String:

date = yyyy/mm/dd
puts "Today's date: #{date}"
text = ["Dates: ", yy/mm, yyyy/mm].join(", ")
text = "A great date: " << date

But in some instances you'll have to expilictly call to_s:

printf "Today's date: %s\n", date.to_s

All the heavy lifting is done by Date#strftime and Date.strptime.

Format Specifiers

The table below lists the available format specifiers. All of these can be separated by one of the supported delimiters: "/", ".", or "-".

Name Format
d day of the year, no 0 padding
dd day of the year
m day of the month, no 0 padding
mm day of the month
y 2 digit year
yy 2 digit year
yyyy 4 digit year

There are also combined, delimiterless functions for all combinations of the above, e.g., ymd, mdy, yymmdd, etc...

Caveats

Due to operator precedence you can't mix delimiters.

Author

Skye Shaw [sshaw AT gmail.com]

License

Released under the MIT License: www.opensource.org/licenses/MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].