Skip to content

Commit 74a99da

Browse files
committed
Using SubscriptionStats.lastTryIsoDate instead of SubscriptionStats.lastTryDate
1 parent de5338b commit 74a99da

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

src/core/SubscriptionUpdater.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ export class SubscriptionUpdater {
8585
let interval = subscription.refreshRate * 60 * 1000;
8686
let firstFetchTimeoutMs: number;
8787

88-
if (subscription.stats?.lastTryDate) {
89-
const timeSinceLastTry = Date.now() - (new Date(subscription.stats.lastTryDate)).getTime();
88+
if (subscription.stats?.lastTryIsoDate) {
89+
const timeSinceLastTry = Date.now() - (new Date(subscription.stats.lastTryIsoDate)).getTime();
9090

9191
firstFetchTimeoutMs = Math.max(0, interval - timeSinceLastTry);
9292
} else {
@@ -265,8 +265,8 @@ export class SubscriptionUpdater {
265265
let interval = subscription.refreshRate * 60 * 1000;
266266
let firstFetchTimeoutMs: number;
267267

268-
if (subscription.stats?.lastTryDate) {
269-
const timeSinceLastTry = Date.now() - (new Date(subscription.stats.lastTryDate)).getTime();
268+
if (subscription.stats?.lastTryIsoDate) {
269+
const timeSinceLastTry = Date.now() - (new Date(subscription.stats.lastTryIsoDate)).getTime();
270270

271271
firstFetchTimeoutMs = Math.max(0, interval - timeSinceLastTry);
272272
} else {

src/core/definitions.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { api, environment } from '../lib/environment';
33
import { Utils } from '../lib/Utils';
44
import { ProfileOperations } from './ProfileOperations';
5-
import { Debug } from '../lib/Debug';
65

76
/*
87
* This file is part of SmartProxy <https://github.com/salarcode/SmartProxy>,
@@ -956,17 +955,19 @@ export enum ProxyServerSubscriptionFormat {
956955
export class SubscriptionStats {
957956
lastSuccessDate: string;
958957
lastTryDate: string;
958+
lastTryIsoDate: string;
959959
lastStatus: boolean;
960960
lastStatusMessage: string;
961961
lastStatusProxyServerName: string;
962962

963963
public static updateStats(stats: SubscriptionStats, success: boolean, errorResult?: any) {
964964
let now = new Date();
965-
stats.lastTryDate = now.toISOString();
965+
stats.lastTryIsoDate = now.toISOString();
966+
stats.lastTryDate = now.toLocaleDateString() + ' ' + now.toLocaleTimeString();
966967
if (success) {
967968
stats.lastStatus = true;
968969
stats.lastStatusMessage = null;
969-
stats.lastSuccessDate = now.toLocaleDateString() + ' ' + now.toLocaleTimeString();
970+
stats.lastSuccessDate = stats.lastTryDate;
970971
}
971972
else {
972973
stats.lastStatus = false;
@@ -985,13 +986,7 @@ export class SubscriptionStats {
985986

986987
if (!stats.lastStatus) {
987988
if (stats.lastTryDate) {
988-
try {
989-
let lastTryDate = new Date(stats.lastTryDate);
990-
let lastTryDateText = lastTryDate.toLocaleDateString() + ' ' + lastTryDate.toLocaleTimeString();
991-
status += `\r\n${api.i18n.getMessage("settingsSubscriptionStatsLastTry")} ${lastTryDateText}`
992-
} catch (error) {
993-
Debug.warn(`SubscriptionStats.lastTryDate has invalid (probably old) value`, error);
994-
}
989+
status += `\r\n${api.i18n.getMessage("settingsSubscriptionStatsLastTry")} ${stats.lastTryDate}`
995990
}
996991
else {
997992
status += `\r\n${api.i18n.getMessage("settingsSubscriptionStatsLastTry")} -`

0 commit comments

Comments
 (0)