time_elapsed 0.2.4+2

  • Readme
  • Changelog
  • Example
  • Installing
  • new77

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 #

Example: #

This example app shows all implementations

App shot

Have a Nice Code!

[0.2.1] - 2020-06-19. #

  • Change Methods return.

[0.2.2] - 2020-06-19. #

  • Change pubspecs section.

[0.2.2+1] - 2020-06-19. #

  • Example task

[0.2.2+3] - 2020-06-19. #

  • Add Dependencies as Cleaner

[0.2.3] - 2020-06-19. #

  • Add Dynamic parsing

[0.2.3+1] - 2020-06-19. #

  • Dynamic parsing

[0.2.3+2] - 2020-06-19. #

  • Docs update

[0.2.3+3] - 2020-06-19. #

  • Docs update

[0.2.4] - 2020-06-20. #

  • Add 'Just Now' 'Now' return for elapsed time less than a minute

[0.2.4+1] - 2020-06-20. #

  • minor ajusts

[0.2.4+2] - 2020-06-20. #

  • Docs ajusts

example/lib/main.dart

import 'package:time_elapsed/time_elapsed.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: HomePage(title: 'Time Elapsed Demo'),
    );
  }
}

class HomePage extends StatelessWidget {
  final String title;

  const HomePage({Key key, this.title}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    // date current as String
    String _timeString = "2020-04-19 03:48:57.063773";

    // date current as DateTime
    DateTime _timeDate = DateTime.parse(_timeString);

    // date current as String
    String _timeStamp = DateTime.now().toString();

    void _incrementCounter() {
      _timeString =
          TimeElapsed().fromDateStr(_timeString); // to calculate from String
      _timeStamp =
          TimeElapsed().fromDateTime(_timeDate); // to calculate from DateTime

      print(_timeString.toString());
      print(_timeStamp.toString());
    }

    print(DateTime.now());

    return Scaffold(
      appBar: AppBar(title: Text(title)),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Container(
            padding: EdgeInsets.symmetric(horizontal: 32, vertical: 16),
            // color: Theme.of(context).primaryColor,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                Card(
                  color: Colors.amber[200],
                  child: Container(
                    padding: EdgeInsets.all(16),
                    child: Text(
                      "from string: " + TimeElapsed().fromDateStr(_timeString),
                      style: TextStyle(fontSize: 24),
                    ),
                  ),
                ),
                Card(
                  color: Colors.amber[200],
                  child: Container(
                    padding: EdgeInsets.all(16),
                    child: Text(
                      "from date type: " +
                          TimeElapsed().fromDateTime(_timeDate),
                      style: TextStyle(fontSize: 24),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Container(
            padding: EdgeInsets.symmetric(vertical: 16),
            child: Column(
              children: [
                Card(
                  color: Theme.of(context).primaryColor,
                  child: Container(
                    padding: EdgeInsets.all(16),
                    child: Text(
                      "date now: \n" + _timeStamp,
                      style: TextStyle(fontSize: 24, color: Colors.white),
                    ),
                  ),
                ),
                Card(
                  color: Theme.of(context).primaryColor,
                  child: Container(
                    padding: EdgeInsets.all(16),
                    child: Text(
                      "date passed: \n" + _timeString,
                      style: TextStyle(fontSize: 24, color: Colors.white),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Container(
            padding: EdgeInsets.symmetric(vertical: 16),
            child: Column(
              children: [
                Card(
                  color: Colors.green[300],
                  child: Container(
                    padding: EdgeInsets.all(16),
                    child: Text(
                      // current time : 2020-06-20 21:56:50.252522
                      "just now: " +
                          TimeElapsed()
                              .fromDateStr("2020-06-20 22:23:14.194374"),
                      style: TextStyle(fontSize: 24),
                    ),
                  ),
                ),
                Card(
                  color: Colors.green[300],
                  child: Container(
                    padding: EdgeInsets.all(16),
                    child: Text(
                      // current time : 2020-06-20 21:56:50.252522
                      "minutes: " +
                          TimeElapsed()
                              .fromDateStr("2020-06-20 21:56:50.252522"),
                      style: TextStyle(fontSize: 24),
                    ),
                  ),
                ),
                Card(
                  color: Colors.green[300],
                  child: Container(
                    padding: EdgeInsets.all(16),
                    child: Text(
                      "hours: " +
                          TimeElapsed()
                              .fromDateStr("2020-06-20 20:56:50.252522"),
                      style: TextStyle(fontSize: 24),
                    ),
                  ),
                ),
                Card(
                  color: Colors.green[300],
                  child: Container(
                    padding: EdgeInsets.all(16),
                    child: Text(
                      "days: " +
                          TimeElapsed()
                              .fromDateStr("2020-06-18 20:56:50.252522"),
                      style: TextStyle(fontSize: 24),
                    ),
                  ),
                ),
                Card(
                  color: Colors.green[300],
                  child: Container(
                    padding: EdgeInsets.all(16),
                    // base time: 2020-06-20 20:56:50.252522
                    child: Text(
                      "week: " +
                          TimeElapsed()
                              .fromDateStr("2020-06-02 20:56:50.252522"),
                      style: TextStyle(fontSize: 24),
                    ),
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  time_elapsed: ^0.2.4+2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:time_elapsed/time_elapsed.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
53
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
pedantic ^1.0.0
test ^1.0.0