Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
FELIPE EDUARDO MORSCHEL committed Jul 20, 2022
0 parents commit 39e88c3
Show file tree
Hide file tree
Showing 14 changed files with 656 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build outputs.
build/

# Omit committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial version.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
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.

## Getting started

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

## Usage

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

```dart
const like = 'sample';
```

## 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.
137 changes: 137 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
include: package:lints/recommended.yaml

analyzer:
plugins:
- dart_code_metrics
exclude:
- "**generated_plugin_registrant.dart"
- "lib/src/database/database.g.dart"
errors:
missing_required_param: error

dart_code_metrics:
rules:
- double-literal-format
- format-comment
- member-ordering-extended:
alphabetize: false
order:
- constructors
- named-constructors
- factory-constructors
- static-getters-setters
- static-const-public-fields
- static-const-private-fields
- static-final-public-fields
- static-final-private-fields
- static-late-final-public-fields
- static-late-final-private-fields
- static-late-public-fields
- static-late-private-fields
- static-public-fields
- static-private-fields
- const-public-fields
- const-private-fields
- final-public-fields
- final-private-fields
- late-final-public-fields
- late-final-private-fields
- late-public-fields
- late-private-fields
- public-fields
- private-fields
- overridden-public-fields
- overriden-public-methods
- static-public-methods
- static-private-methods
- public-methods
- private-methods
- getters-setters
- prefer-commenting-analyzer-ignores
- prefer-first
- prefer-immediate-return
- prefer-last

- always-remove-listener
- avoid-border-all
- avoid-returning-widgets:
ignored-names:
- testFunction
ignored-annotations:
- allowedAnnotation
- avoid-unnecessary-setstate
- avoid-wrapping-in-padding
- prefer-const-border-radius

linter:
rules:
always_declare_return_types: true
always_put_required_named_parameters_first: true
always_require_non_null_named_parameters: true
avoid_double_and_int_checks: true
avoid_dynamic_calls: true
avoid_empty_else: true
avoid_multiple_declarations_per_line: true
avoid_positional_boolean_parameters: true
avoid_slow_async_io: true
avoid_types_on_closure_parameters: true
avoid_unused_constructor_parameters: true
cancel_subscriptions: true
close_sinks: true
directives_ordering: true
empty_constructor_bodies: true
eol_at_end_of_file: true
exhaustive_cases: true
implicit-casts: true
implicit-dynamics: true
join_return_with_assignment: true
leading_newlines_in_multiline_strings: true
noop_primitive_operations: true
prefer_collection_literals: true
prefer_final_in_for_each: true
prefer_final_locals: true
prefer_for_elements_to_map_fromIterable: true
prefer_function_declarations_over_variables: true
prefer_inlined_adds: true
prefer_int_literals: true
prefer_is_empty: true
prefer_is_not_empty: true
prefer_is_not_operator: true
prefer_iterable_whereType: true
prefer_null_aware_method_calls: true
prefer_null_aware_operators: true
prefer_relative_imports: true
prefer_single_quotes: true
prefer_spread_collections: true
prefer_typing_uninitialized_variables: true
prefer_void_to_null: true
require_trailing_commas: true
sized_box_shrink_expand: true
sort_constructors_first: true
sort_unnamed_constructors_first: true
type_init_formals: true
unawaited_futures: true
unnecessary_constructor_name: true
unnecessary_getters_setters: true
unnecessary_lambdas: true
unnecessary_late: true
unnecessary_new: true
unnecessary_null_aware_assignments: true
unnecessary_null_in_if_null_operators: true
unnecessary_parenthesis: true
unnecessary_statements: true
unnecessary_this: true
use_colored_box: true
use_decorated_box: true
use_enums: true
use_function_type_syntax_for_parameters: true
use_if_null_to_convert_nulls_to_bools: true
use_is_even_rather_than_modulo: true
use_late_for_private_fields_and_variables: true
use_named_constants: true
use_setters_to_change_properties: true
use_string_buffers: true
use_super_parameters: true
use_test_throws_matchers: true
use_to_and_as_if_applicable: true
void_checks: true
9 changes: 9 additions & 0 deletions lib/due_date.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// Support for doing something awesome.
///
/// More dartdocs go here.
library due_date;

export 'src/due_date.dart';
export 'src/due_date_base.dart';
export 'src/enums.dart';
export 'src/extensions.dart';
73 changes: 73 additions & 0 deletions lib/src/due_date.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:time/time.dart';

class DueDateTime extends DateTime {
factory DueDateTime(int dueDay, [DateTime? startReference]) {
final reference = (startReference ?? DateTime.now()).date;
late final DateTime dueDate;
if (reference.day == dueDay) {
return DueDateTime._toConstructor(dueDay, reference);
} else if (reference.day < dueDay) {
if (reference.lastDayOfMonth.day > dueDay) {
dueDate = reference
.to(reference.lastDayOfMonth)
.firstWhere((date) => date.day == dueDay);
return DueDateTime._toConstructor(dueDay, dueDate);
} else {
dueDate = reference
.copyWith(day: dueDay)
.clamp(max: reference.lastDayOfMonth);
return DueDateTime._toConstructor(dueDay, dueDate);
}
} else {
final dueNextMonth =
reference.copyWith(month: reference.month + 1, day: dueDay);
final endNextMonth =
reference.copyWith(month: reference.month + 1, day: 1).lastDayOfMonth;
dueDate = dueNextMonth.clamp(max: endNextMonth);
return DueDateTime._toConstructor(dueDay, dueDate);
}
}

DueDateTime._(this.dueDay, DateTime date)
: super(
date.year,
date.month,
date.day,
date.hour,
date.minute,
date.second,
date.millisecond,
date.microsecond,
);

DueDateTime._utc(this.dueDay, DateTime date)
: super.utc(
date.year,
date.month,
date.day,
date.hour,
date.minute,
date.second,
date.millisecond,
date.microsecond,
);

factory DueDateTime._toConstructor(int dueDay, DateTime date) {
return date.isUtc
? DueDateTime._utc(dueDay, date)
: DueDateTime._(dueDay, date);
}

int dueDay;

DueDateTime addMonths([int months = 1]) {
final firstDay = copyWith(month: month + months, day: 1);
return DueDateTime._toConstructor(
dueDay,
firstDay.copyWith(day: dueDay).clamp(
min: firstDay,
max: firstDay.lastDayOfMonth,
),
);
}
}
11 changes: 11 additions & 0 deletions lib/src/due_date_base.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// Checks if you are awesome. Spoiler: you are.
abstract class DueDateBase {
const DueDateBase(this.dueDay);

final int dueDay;

DueDateBase addMonths(int months);
DueDateBase subtractMonths(int months);
DueDateBase get next;
DueDateBase get previous;
}
Loading

0 comments on commit 39e88c3

Please sign in to comment.