English | Chinese

DayDart

Time-handling library with day.js API.

https://img.shields.io/github/license/csjiabin/daydart.svg https://img.shields.io/github/issues/csjiabin/daydart.svg

Getting Started

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Install

Run this command under your project

dart pub add daydart
# or
flutter pub add daydart

API

The DayDart object is immutable, and all calls will return a new DayDart object.


Parsing

Passing in the supported format in DayDart.

Now Time

Calling DayDart() with no arguments returns a new DayDart object containing the current date and time

DayDart now = DayDart()

String

Parses the given string in ISO 8601 format and returns an instance of the DayDart object.

DayDart('2018-04-04')

DateTime

A DateTime object passed in.

DayDart(DateTime.now());

Timestamp

Create DayDart with an integer value of milliseconds

DayDart(1623484401193);

Clone

All DayDart objects are immutable. Dayart#clone can still create a clone of the current object if needed.

DayDart a = DayDart()
DayDart b = a.clone()

Calling DayDart() on the DayDart object also clones it.

DayDart a = DayDart()
DayDart b = DayDart(a)

Valid

Returns a Boolean indicating whether the DayDart object contains an expiration date.

DayDart().isValid()

Get

Year

Gets or sets the year.

DayDart().year();
DayDart().year(2000);

Month

Gets or sets the month.

Accept numbers from 1 to 12. If it exceeds that range, it will continue until the end of the year.

DayDart().month();
DayDart().month(1);

Quarter

Gets or sets the quarter.

DayDart('2010-04-01').quarter() // 2
DayDart('2010-04-01').quarter(2)

Day

Gets or sets the date of the month.

Accept numbers from 1 to 31. If this range is exceeded, it will last until the day.

DayDart().day()
DayDart().day(1)

Days

Gets the total number of days of the month

DayDart().days()

DayOfYear

Total number of days from date to year

DayDart().dayOfYear()

Weeks

Gets the total number of weeks from the date to the beginning of the year

DayDart().weeks()

Week

For week

DayDart().week()

Hour

Gets or sets the hour.

Accept the numbers from 0 to 59. If this range is exceeded, it will last until the day.

DayDart().hour()
DayDart().hour(12)

Minute

Gets or sets the minutes.

Accept the numbers from 0 to 59. If this range is exceeded, it will last until hours

DayDart().minute()
DayDart().minute(12)

Second

Gets or sets the seconds.

Accept the numbers from 0 to 59. If this range is exceeded, it will last up to minutes.

DayDart().second()
DayDart().second(12)

Millisecond

Gets or sets milliseconds.

Accepts numbers from 0 to 999. If this range is exceeded, it will last up to seconds.

DayDart().millisecond()
DayDart().millisecond(12)

Operation

Once you have a DayDart object, you might want to manipulate it in some way.

DayDart supports method links like this:

DayDart('2019-01-25')..add(1, DayUnits.D)..subtract(1, DayUnits.y)..year(2009)..toString()

List of all available units

unidesc
Dday (1-31)
Mmonth(1-12)
yyear
hhour
mminutes
sseconds
msmillisecond

Add

Returns a cloned DayDart object, adding the specified time.

DayDart().add(7, DayUnits.D)

Subtract

Returns the cloned 'DayDart' object, subtracting the specified time.

DayDart().subtract(7, DayUnits.D)

Query

List of all available units

unitdesc
Dday
Mmonth
yyear
hhour
mminutes
sseconds
msmillisecond

isBefore

This indicates whether the DayDart object is before another supplied date-time.

DayDart().isBefore(DayDart('2011-01-01')) // default milliseconds

If you want to limit granularity to units rather than milliseconds, pass it as a second argument.

DayDart().isBefore('2011-01-01', DayUnits.y)

isSame

This indicates whether the DayDart object is the same as the date-time provided by another.

DayDart().isSame(DayDart('2011-01-01')) // default milliseconds

If you want to limit granularity to units rather than milliseconds, pass it as a second argument.

DayDart().isSame('2011-01-01', DayUnits.y)

isAfter

This indicates whether the DayDart object is after another supplied date-time.

DayDart().isAfter(DayDart('2011-01-01')) // default milliseconds

If you want to limit granularity to units rather than milliseconds, pass it as a second argument.。

DayDart().isAfter('2011-01-01', DayUnits.y)

isSameOrBefore

This indicates whether the DayDart object is the same or before another provided date-time.

DayDart().isSameOrBefore(DayDart('2011-01-01')) // default milliseconds

If you want to limit granularity to units rather than milliseconds, pass it as a second argument.

DayDart().isSameOrBefore('2011-01-01', DayUnits.y)

isSameOrAfter

This indicates whether the DayDart object is the same or after another supplied date-time.

DayDart().isSameOrAfter(DayDart('2011-01-01')) // default milliseconds

If you want to limit granularity to units rather than milliseconds, pass it as a second argument.

DayDart().isSameOrAfter('2011-01-01', DayUnits.y)

isBetween

This indicates whether the DayDart object is between the other two supplied date-times.

DayDart('2010-10-20').isBetween('2010-10-19', DayDart('2010-10-25'))// default milliseconds

If you want to limit granularity to units rather than milliseconds, pass it as a third parameter.

DayDart().isBetween('2010-10-19', '2010-10-25', DayUnits.y)

isDayDart

This indicates whether the variable is a DayDart object.

DayDart.isDayDart(DayDart()) // true
DayDart.isDayDart(DateTime.now()) // false

You can also use the is operator:

DayDart() is DayDart // true

isLeapYear

This indicates whether the year of the DayDart object is a leap year.

DayDart('2000-01-01').isLeapYear() // true

Display

Format

Gets the formatted date based on the passed token string.

To escape characters, enclose them in square brackets (for example, 'MM').

DayDart().format()

DayDart('2019-01-25').format('dd/MM/yyyy') // '25/01/2019'

A list of all available parse tags

argdesc
dDAY
EABBR_WEEKDAY
EEEEWEEKDAY
LLLABBR_STANDALONE_MONTH
LLLLSTANDALONE_MONTH
MNUM_MONTH
MdNUM_MONTH_DAY
MEdNUM_MONTH_WEEKDAY_DAY
MMMABBR_MONTH
MMMdABBR_MONTH_DAY
MMMEdABBR_MONTH_WEEKDAY_DAY
MMMMMONTH
MMMMdMONTH_DAY
MMMMEEEEdMONTH_WEEKDAY_DAY
QQQABBR_QUARTER
QQQQQUARTER
yYEAR
yMYEAR_NUM_MONTH
yMdYEAR_NUM_MONTH_DAY
yMEdYEAR_NUM_MONTH_WEEKDAY_DAY
yMMMYEAR_ABBR_MONTH
yMMMdYEAR_ABBR_MONTH_DAY
yMMMEdYEAR_ABBR_MONTH_WEEKDAY_DAY
yMMMMYEAR_MONTH
yMMMMdYEAR_MONTH_DAY
yMMMMEEEEdYEAR_MONTH_WEEKDAY_DAY
yQQQYEAR_ABBR_QUARTER
yQQQQYEAR_QUARTER
HHOUR24
HmHOUR24_MINUTE
HmsHOUR24_MINUTE_SECOND
jHOUR
jmHOUR_MINUTE
jmsHOUR_MINUTE_SECOND
mMINUTE
msMINUTE_SECOND
sSECOND

To DateTime

To get a copy of the local date object parsed from the 'dayDart' object, use dayDart #toDate.

DayDart('2019-01-25').toDate()

To List

DayDart('2019-01-25').toList() // [ 2019, 0, 25, 0, 0, 0, 0 ]

To Map

Returns Map with date property.

DayDart('2019-01-25').toMap()
/*
{
  years: 2019,
  months: 0,
  date: 25,
  hours: 0,
  minutes: 0,
  seconds: 0,
  milliseconds: 0
}
*/

To IOS 8601 String

Formatted as an ISO 8601 string.

DayDart('2019-01-25').toISOString() // 2019-01-25T00:00:00.000

To String

Returns a string representation of the date.

DayDart('2019-01-25').toString() // 2019-01-25 00:00:00.000

Stargazers over time

This project will be updated continuously. Your valuable comments are welcome.

Issues

Libraries

daydart