Skip to content

Commit

Permalink
Merge pull request #14 from aarranz/feature/moment-substract
Browse files Browse the repository at this point in the history
Use moment subtract to calculate fromDate instead of making a manual subtract
  • Loading branch information
aarranz committed Nov 18, 2020
2 parents 2c6f22c + f0a808d commit 7a71cf1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<operator xmlns="http://wirecloud.conwet.fi.upm.es/ns/macdescription/1" vendor="FICODES" name="quantumleap-source" version="0.1.9rc2">
<operator xmlns="http://wirecloud.conwet.fi.upm.es/ns/macdescription/1" vendor="FICODES" name="quantumleap-source" version="0.2.0">
<details>
<title>QuantumLeap source</title>
<homepage>https://github.com/Ficodes/quantumleap-source-operator</homepage>
Expand Down
8 changes: 4 additions & 4 deletions src/js/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* quantumleap-source
*
* Copyright (c) 2019 Future Internet Consulting and Development Solutions S.L.
* Copyright (c) 2020 Future Internet Consulting and Development Solutions S.L.
* Apache License 2.0
*
*/
Expand Down Expand Up @@ -165,9 +165,9 @@
if (numberOfHours4History > 0 || from !== "" || to !== "") {

if (from === "" && to === "") {
let historicLenght = parseInt(numberOfHours4History) * 60 * 60 * 1000;
to = moment().utc().valueOf();
from = moment(to - historicLenght).valueOf();
let toDate = moment().utc();
to = toDate.valueOf();
from = toDate.subtract(numberOfHours4History, 'hours').valueOf();
} else {
if (from !== null && moment(from).isValid()) {
from = moment(from).valueOf();
Expand Down
16 changes: 8 additions & 8 deletions tests/js/QuantumLeapSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
var historical_length = 24;

let historicLenght = historical_length * 60 * 60 * 1000;
var expected_historicalTo = moment(todayMockValue).utc().valueOf();
var expected_historicalFrom = moment(expected_historicalTo - historicLenght).valueOf();
var attrListMockString = 'attr1, attr2';
var attrListMock = ['attr1', 'attr2'];
var historical_serverMock = 'https://quantumpleap.example.com';
var ngsi_serverMock = 'https://orion.example.com';
var ngsi_tenant = 'Tenant';
var ngsi_service_pathMock = '/Spain/Madrid';
const expected_historicalTo = realMoment(todayMockValue).utc().valueOf();
const expected_historicalFrom = realMoment(todayMockValue).utc().subtract(historical_length, 'hour').valueOf();
const attrListMockString = 'attr1, attr2';
const attrListMock = ['attr1', 'attr2'];
const historical_serverMock = 'https://quantumpleap.example.com';
const ngsi_serverMock = 'https://orion.example.com';
const ngsi_tenant = 'Tenant';
const ngsi_service_pathMock = '/Spain/Madrid';

let expectedQLRequest = {
method: "GET",
Expand Down

0 comments on commit 7a71cf1

Please sign in to comment.