Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
/ dad Public archive

📅 Dad was born for 17 events. It lets date set made easy and testable.

License

Notifications You must be signed in to change notification settings

17media/dad

Repository files navigation

Why Is Calling Dad?

Dad pronounces like "Date"

Why Use Dad

  • Humans readable code
  • Easy for testing
  • Works in Node and Browser

Installation

$ yarn add github:17media/dad\#latest

Convention

dad's API interface always input seconds and return seconds

Usage

import dad from '@17media/dad'

dad('2017-12-12').tw

// or
import { tw } from '@17media/dad'

tw('2017-12-12')
// 1513036800

tw(1514736000)
// {
//   year: 2018,
//   month: 0,
//   date: 1,
//   hours: 0,
//   minutes: 0,
//   seconds: 0,
//   day: 1
// }

tw(1514736000).format('YYYY/MM/DD hh:mm:ss') //  2018/01/01 00:00:00

Valid date format

  • YYYY-MM-DD
  • YYYY-MM-DD HH
  • YYYY-MM-DD HH:mm
  • YYYY-MM-DD HH:mm:ss

You can omit HH:mm:ss, dad will help you auto suffix 00.

Regions

Current works regions for event:

tw, hk and ja

API

Utils

isToday(seconds)

Check seconds timestamp whether same as Today, this is helpful for vote feature.

now()

now is very useful for testing, you can feel free to hard-code current time.

In Browser, pass URL querystring:

?dad.now=2017-12-12 19:00

In Node:

$ ndoe entry.js --dad.now="2017-12-12 19:00"

pass --auto lets time go on:

In Browser:

?dad.now=2017-12-12 19:00&auto

In Node:

$ ndoe entry.js --dad.now=2017-12-12T19:00 --auto