GithubHelp home page GithubHelp logo

allansrc / time_elapsed Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 1.0 309 KB

This package provides a way to facility how you getting elapsed time from a DateTime data. More applied to check how long from now an event happened.

Home Page: http://allansrc.com.br

License: BSD 3-Clause "New" or "Revised" License

Kotlin 0.68% Swift 2.21% Objective-C 0.21% Dart 90.76% HTML 6.14%
flutter dart ios android web desktop time-elapsed package datetime time

time_elapsed's Introduction

TimeElapsed pub package

This package provides a way to facility how you getting elapsed time from a DateTime data. More applied to check how long from now an event happened.

Default:

It return elapsed time by Weeks, Days, Hours and Minutes

How to use:

The package has a two method to get date time elapsed: fromDateStr() and fromDateTime() You can also use a dynamic parsin method: elapsedTimeDynamic()

You can pass it as String or DateTime type:

  String timeString = "2020-04-19 03:48:57.063773"; // set a String type var with Date sample
  DateTime timeDate = DateTime.parse("2020-04-19 03:48:57.063773"); // set a DateTime var sample

  // to calculate from String
  String timeStamp = TimeElapsed.fromDateStr(timeString); // returns 8w (cos now days:2020-06-19)

  // to calculate from DateTime
  String timeStamp = TimeElapsed.fromDateTime(timeDate); // returns 8w (cos now days: 2020-06-19)

If you do not know what type data is, (String or DateTime):

  // to calculate from both, DateTime or String
  String timeStamp = TimeElapsed.elapsedTimeDynamic(timeDate); // returns 8w (cos now days: 2020-06-19)

both methods will return the time elapsed as String

Using Custom Markers for Time (Days, weeks, hours etc...)

To adds a custom texts or change the text near to period elapsed you can use .toCustomTimeElapsed() method. This method receives an object from CustomTimeElapsed class which contains all period we use.

// custom Time String marker
   final customDate = CustomTimeElapsed(
      minutes: 'minutos',
      hours: 'horas',
      days: 'dias',
      now: 'agora',
      seconds: 'segundos',
      weeks: 'semanas',
    );

// Widget that output "76 semanas" instead of "76w"
Text(TimeElapsed.fromDateStr(_timeString).toCustomTimeElapsed(customDate))

_

In another hand, if you prefer, you can pass as params too using .toCustomWDHMS().

toCustomWDHMS(
      minutes: 'minutos',
      hours: 'horas',
      days: 'dias',
      now: 'agora',
      seconds: 'segundos',
      weeks: 'semanas',
    )

Example:

This example app shows all implementations

App shot

Have a Nice Code!

time_elapsed's People

Contributors

allansrc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

francisnnumbi

time_elapsed's Issues

Null Safety

when i try to use TimeElapsed i get this Error:

Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

  • package:time_elapsed
    2

For solutions, see https://dart.dev/go/unsound-null-safety

is there plans to add null safety to this package ?

thank you

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.