Skip to content

Commit

Permalink
some code change
Browse files Browse the repository at this point in the history
  • Loading branch information
samithe7 committed Apr 18, 2024
1 parent 6d2f0b6 commit a9ca679
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
first relise
25 changes: 24 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
TODO: Add your license here.

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,flutter pub pubk
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,34 @@ and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.


## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.

A widget give time info

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.
Simple and eazy

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.


```dart
const like = 'sample';
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
return TimeInfo (time: DateTime.now(),);
}
}
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.

if you have any problem report a issue
70 changes: 36 additions & 34 deletions lib/time_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library time_info;
import 'dart:async' show Timer;
import 'dart:developer' show log;

import 'package:flutter/widgets.dart';
import 'package:flutter/widgets.dart' show BuildContext, State, StatefulWidget, Text, TextStyle, Widget;
import 'package:intl/intl.dart';

/// A Calculator.
Expand All @@ -23,6 +23,40 @@ class TimeInfo extends StatefulWidget {
final String? languageCode;



static ({String? time, bool previusYear}) getTimeAgo(
{required DateTime givenTime}) {
final now = DateTime.now();

log('${givenTime.year} == ${now.year}');
if (givenTime.year == now.year) {
late String? timeAgo;

final difference = now.difference(givenTime).inMinutes;

if (givenTime.day == now.day) {
if (difference < 1) {
timeAgo = 'now';
} else if (difference < 60) {
timeAgo = '${difference}m';
} else if (difference < 1440) {
final hours = (difference / 60).floor();
timeAgo = '${hours}h';
}
} else {
timeAgo = null;

// final months = (difference / 43200).floor();
// timeAgo = '$months months ago';
}

return (time: timeAgo, previusYear: false);
} else {
return (previusYear: true, time: '');
}
}


@override
State<TimeInfo> createState() => _TimeInfoState();
}
Expand All @@ -41,7 +75,7 @@ class _TimeInfoState extends State<TimeInfo> {
void initState() {
super.initState();

info = _Time.getTimeAgo(givenTime: widget.time);
info = TimeInfo .getTimeAgo(givenTime: widget.time);

if (info.previusYear == false &&
info.time != null &&
Expand Down Expand Up @@ -86,36 +120,4 @@ class _TimeInfoState extends State<TimeInfo> {



abstract class _Time {
static ({String? time, bool previusYear}) getTimeAgo(
{required DateTime givenTime}) {
final now = DateTime.now();

log('${givenTime.year} == ${now.year}');
if (givenTime.year == now.year) {
late String? timeAgo;

final difference = now.difference(givenTime).inMinutes;

if (givenTime.day == now.day) {
if (difference < 1) {
timeAgo = 'now';
} else if (difference < 60) {
timeAgo = '${difference}m';
} else if (difference < 1440) {
final hours = (difference / 60).floor();
timeAgo = '${hours}h';
}
} else {
timeAgo = null;

// final months = (difference / 43200).floor();
// timeAgo = '$months months ago';
}

return (time: timeAgo, previusYear: false);
} else {
return (previusYear: true, time: '');
}
}
}
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: time_info
description: "A new Flutter package project."
version: 0.0.1
repository:
description: "A widget give you time info"
version: 0.0.2
repository: https://github.com/samithe7/time_info
homepage:

environment:
sdk: '>=3.4.0-282.1.beta <4.0.0'
sdk: '>=3.3.4 <4.0.0'
flutter: ">=1.17.0"

dependencies:
Expand Down

0 comments on commit a9ca679

Please sign in to comment.