GithubHelp home page GithubHelp logo

nixrajput / get-time-ago Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 20.0 6.36 MB

A Flutter package to convert and format DateTime object into get_time_ago format to get String like 10 seconds ago, a minute ago, 7 hours ago, etc.

Home Page: https://pub.dev/packages/get_time_ago

License: MIT License

Dart 86.94% Kotlin 0.71% Swift 1.08% Objective-C 0.10% HTML 11.17%
flutter get-time-ago time-ago datetime datetime-format pub flutterdev datetime-to-string timago packages

get-time-ago's Introduction

get_time_ago

A Flutter package to convert and format DateTime object into get_time_ago format to get
String like 10 seconds ago, a minute ago, 7 hours ago, etc.

pub package Stars Forks Watchers Contributors CI

GitHub release (latest by date) GitHub last commit GitHub issues GitHub pull requests GitHub Licence

Table of Contents

Demo

View Demo

Installation

Add get_time_ago as a dependency in your pubspec.yaml file.

dependencies:
  get_time_ago: ^latest_version

Usage

Format any DateTime object into get_time_ago format by following steps:

// Import the plugin
import 'package:get_time_ago/get_time_ago.dart';

// Pass DateTime object as argument in the method
var _dateTime = DateTime.now().subtract(const Duration(minutes: 10)); // [DateTime] object
print(GetTimeAgo.parse(_dateTime)); // 10 minutes ago

// Formatting with locale
print(GetTimeAgo.parse(_dateTime, locale:'es')); // hace 10 minutos

Formatting String as get_time_ago

If you have saved a DateTime object as a String into a variable, database or cloud, then you have to first convert the String into DateTime object and then pass it as argument in parse method of get_time_ago plugin to format it into get_time_ago format by following steps:

// Import the plugin
import 'package:get_time_ago/get_time_ago.dart';

var _timestamp = '2021-05-10 05:21:37.712498'; // [DateTime] formatted as String.
var _convertedTimestamp = DateTime.parse(_timestamp); // Converting into [DateTime] object
var result = GetTimeAgo.parse(_convertedTimestamp); 
print(result);

Setting default locale

If you want to change your default locale, then call setDefaultLocale method and pass the locale code as the argument.

// Import the plugin
import 'package:get_time_ago/get_time_ago.dart';

@override
void initState() {
  super.initState();
  GetTimeAgo.setDefaultLocale('fr'); // Sets the default locale to French
}

Setting Custom Locale & Messages

Implementing and Adding Custom Messages

class CustomMessages implements Messages {
  @override
  String prefixAgo() => '';

  @override
  String suffixAgo() => 'ago';

  @override
  String secsAgo(int seconds) => '$seconds seconds';

  @override
  String minAgo(int minutes) => 'a minute';

  @override
  String minsAgo(int minutes) => '$minutes minutes';

  @override
  String hourAgo(int minutes) => 'an hour';

  @override
  String hoursAgo(int hours) => '$hours hours';

  @override
  String dayAgo(int hours) => 'a day';

  @override
  String daysAgo(int days) => '$days days';

  @override
  String wordSeparator() => ' ';
}

Overriding en Locale Messages with Custom Messages

GetTimeAgo.setCustomLocaleMessages('en', CustomMessages());

Contributors

Nikhil Rajput
Nikhil Rajput

๐Ÿ’ฌ ๐Ÿ“– ๐Ÿšง ๐Ÿš‡ ๐Ÿ‘€ ๐Ÿ“ข
Mejans
Mejans

๐Ÿ“– ๐Ÿ‘€
Muhammad Salman Bediya
Muhammad Salman Bediya

๐Ÿ“– ๐Ÿ‘€
fluxion8
fluxion8

๐Ÿ“– ๐Ÿ‘€
Pascal Otto
Pascal Otto

๐Ÿ“– ๐Ÿ‘€
june lee
june lee

๐Ÿ“– ๐Ÿ‘€
ywake
ywake

๐Ÿ“– ๐Ÿ‘€
Jiduo Zhang
Jiduo Zhang

๐Ÿ“– ๐Ÿ‘€
silviuilas
silviuilas

๐Ÿ“– ๐Ÿ‘€
Rexios
Rexios

๐Ÿ“– ๐Ÿ‘€
Minh-Danh
Minh-Danh

๐Ÿ“– ๐Ÿ‘€
Ilham solehudin
Ilham solehudin

๐Ÿ“– ๐Ÿ‘€
WingCH
WingCH

๐Ÿ“– ๐Ÿ‘€

Contributing

If you would like to contribute to this project, feel free to fork the repository, make your changes, and submit a pull request. Please follow the guidelines in the CONTRIBUTING.md file.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Sponsor Me

  • By sponsoring my efforts, you're not merely contributing to the development of my projects; you're investing in its growth and sustainability.
  • Your support empowers me to dedicate more time and resources to improving the project's features, addressing issues, and ensuring its continued relevance in the rapidly evolving landscape of technology.
  • Your sponsorship directly fuels innovation, fosters a vibrant community, and helps maintain the project's high standards of quality. Together, we can shape the future of the projects and make a lasting impact in the open-source community.
  • Thank you for considering sponsoring my work!

Sponsor

Connect With Me

GitHub: nixrajput Linkedin: nixrajput Instagram: nixrajput Twitter: nixrajput07 Telegram: nixrajput Gmail: nkr.nikhi.nkr@gmail.com

Activities

Alt

get-time-ago's People

Contributors

fluxion8 avatar harloom avatar kidozh avatar mejans avatar melodysdreamj avatar minhdanh avatar msalman2890 avatar nikhil-merito avatar nixrajput avatar pascalotto avatar rexios80 avatar silviuilas avatar wingch avatar ywake avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

get-time-ago's Issues

[Bug]: 0 seconds ago

Contact Details

[email protected]

What happened?

In a very short period of time I hope that in a very short period of time, such as less than 2 seconds, or even when the gap is negative, it will display: just

Version

last

What devices are you seeing the problem on?

Android

OS

android 11

Relevant log output

0 seconds ago

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Feature Request]: Add Test Cases

Contact Details

[email protected]

Is your feature request related to a problem? Please describe.

No, this feature request is not related to any problem. I am looking to add test cases to this project, but due to lack of time, I am unable to complete it individually.

Describe the solution you'd like

I am the owner of this project and I am inviting every open-source contributor to contribute to my project so that I can focus on my other projects.

Describe alternatives you've considered

If anyone is interested in adding test cases, I want to thank him/her in advance.
Also, I would mention the name of every contributor to this project.

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Suggest an idea for this project

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

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.