Skip to content

Commit

Permalink
Fix negative year problem
Browse files Browse the repository at this point in the history
  • Loading branch information
EsTharian committed Apr 27, 2021
1 parent 15cc0f4 commit 2699d13
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/Counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var Counter = /** @class */ (function () {
}
};
Counter.prototype.fullYear = function (now) {
var fullYear = this.upDownFixer * (this.datetime.getFullYear() - now.getFullYear()) - Math.max(0, this.upDownFixer);
var fullYear = Math.floor((this.fullDay(now) / 365));
this.render(this.options.fullYearDOM, fullYear);
return fullYear;
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "count-helper",
"version": "2.0.1",
"version": "2.0.2",
"description": "Time count helper with vanilla Javascript",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
28 changes: 22 additions & 6 deletions src/Counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Counter implements ICounter {
}

fullYear(now: Date): number {
const fullYear = this.upDownFixer * (this.datetime.getFullYear() - now.getFullYear()) - Math.max(0, this.upDownFixer);
const fullYear = Math.floor((this.fullDay(now) / 365));
this.render(this.options.fullYearDOM, fullYear);
return fullYear;
}
Expand Down Expand Up @@ -112,11 +112,27 @@ export class Counter implements ICounter {
const now = new Date();

const seconds = Math.round((time - self.start) / 1000);
self.second(now);
self.minute(now);
self.hour(now);
self.day(now);
self.year(now);

if (self.options.secondDOM || self.options.fullSecondDOM) {
self.second(now);
}

if (self.options.minuteDOM || self.options.fullMinuteDOM) {
self.minute(now);
}

if (self.options.hourDOM || self.options.fullHourDOM) {
self.hour(now);
}

if (self.options.dayDOM || self.options.fullDayDOM) {
self.day(now);
}

if (self.options.yearDOM || self.options.fullYearDOM) {
self.year(now);
}

const targetNext = (seconds + 1) * 1e3 + self.start;

if (!self.stop) {
Expand Down

0 comments on commit 2699d13

Please sign in to comment.