Code Monkey home page Code Monkey logo

const-date-time's Introduction

const_date_time

Build Status Code Coverage Funding Status

A drop-in replacement for Dart's DateTime class with const constructors.

Getting started

Install the package:

flutter pub add const_date_time

or

dart pub add const_date_time

Usage

You can use a ConstDateTime anywhere a DateTime is expected. All major DateTime constructors have a const version.

import 'package:const_date_time/const_date_time.dart';

// const constructors
final year = const ConstDateTime(2022);
final date = const ConstDateTime(2022, 10, 27);
final dateTime = const ConstDateTime(2022, 10, 27, 12, 34, 56, 789, 10);

final yearUtc = const ConstDateTime.utc(2022);
final dateUtc = const ConstDateTime.utc(2022, 10, 27);
final dateTimeUtc = const ConstDateTime.utc(2022, 10, 27, 12, 34, 56, 789, 1011);

final ms = const ConstDateTime.fromMillisecondsSinceEpoch(1666931562000);
final msUtc = const ConstDateTime.fromMillisecondsSinceEpoch(1666931562000, isUtc: true);

final us = const ConstDateTime.fromMicrosecondsSinceEpoch(1666931562000000);
final usUtc = const ConstDateTime.fromMicrosecondsSinceEpoch(1666931562000000, isUtc: true);

You can access the underlying DateTime object directly:

final cdt = const ConstDateTime(2022);
final DateTime dt = cdt.dateTime;
// other getters are available as well:
final int dtYear = dt.year;
final int dtWeekday = dt.weekday;

Don't forget other DateTime methods too!

final constDateTime = const ConstDateTime(2022);

constDateTime.add(Duration(minutes: 5));
constDateTime.toIso8601String();

Sponsor

Please consider sponsoring my work to ensure this library receives the attention it deserves.

License

const_date_time is released under the MIT License.

const-date-time's People

Contributors

ipcjs avatar ohitsdaniel avatar westy92 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

ipcjs ohitsdaniel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.