Skip to content

Commit 3db5930

Browse files
author
alfredbrockotter
committed
fix: MomentJS is no longer needed as dependency
1 parent 038eb61 commit 3db5930

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/services/CacheService.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import moment from 'moment';
2-
31
export default class CacheService {
42
constructor(cacheEntries) {
53
if (!(cacheEntries instanceof Array)) {
@@ -21,22 +19,21 @@ export default class CacheService {
2119
// If on client, check if a cache entry it present
2220
if (query && !process.server) {
2321
let key = (cacheKey && cacheKey !== '') ? cacheKey : query.getUrl();
24-
2522
let cacheEntry = getCacheEntry(this.cacheEntries, key);
2623

2724
// return from cache
28-
if (cacheEntry && moment.duration(moment().diff(cacheEntry.timestamp)).asSeconds() < seconds) {
25+
if (cacheEntry && getDiffInSeconds(new Date(), cacheEntry.timestamp) < seconds) {
2926
return new Promise(function (resolve, reject) {
3027
resolve(cacheEntry.object);
3128
});
3229
}
3330
else {
3431
return query.getPromise().then(response => {
3532
if (cacheEntry) {
36-
cacheEntry.timestamp = moment();
33+
cacheEntry.timestamp = new Date();
3734
}
3835
else {
39-
this.cacheEntries.push({ key: key, object: response, seconds: seconds, timestamp: moment() });
36+
this.cacheEntries.push({ key: key, object: response, seconds: seconds, timestamp: new Date() });
4037
}
4138
return response;
4239
});
@@ -55,3 +52,10 @@ const getCacheEntry = (entries, key) => {
5552
}
5653
return null;
5754
};
55+
56+
const getDiffInSeconds = (t1, t2) => {
57+
let dif = t1.getTime() - t2.getTime();
58+
let secondsFromT1ToT2 = dif / 1000;
59+
let secondsBetweenDates = Math.abs(secondsFromT1ToT2);
60+
return secondsBetweenDates;
61+
};

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
},
4444
"homepage": "https://github.com/Domitnator/kenticocloud-nuxt-module#readme",
4545
"dependencies": {
46-
"kentico-cloud-delivery": "^4.2.1",
47-
"moment": "^2.22.2"
46+
"kentico-cloud-delivery": "^4.2.1"
4847
},
4948
"devDependencies": {
5049
"babel-plugin-external-helpers": "^6.22.0",

0 commit comments

Comments
 (0)