Permalink
Browse files

fix(rest): use negative offset for dates to work around a server issue

  • Loading branch information...
RangerRick committed Aug 16, 2017
1 parent 9b79121 commit abdfc0bc264f0f1f4a86815c52f9e6e894f7b1e2
@@ -26,7 +26,7 @@ export class V2FilterProcessor implements IFilterProcessor {
* This must be explicitly set as the restriction value when using
* either the NULL or NOTNULL comparators on date fields.
*/
public static NULL_DATE = '1970-01-01T00:00:00.000+0000';
public static NULL_DATE = '1970-01-01T00:00:00.000-0000';
/** The accessor for Properties */
private searchPropertyAccessor: ISearchPropertyAccessor;
View
@@ -64,20 +64,9 @@ export class Util {
public static toDateString(date: Date|Moment|number) {
const ret = Util.toMoment(date);
if (ret) {
return ret.utc().format(dateFormat);
return ret.utc().format(dateFormat).replace('+0000', '-0000');
} else {
return undefined;
}
}
/**
* Encodes the parameters.
* @param pramaters the parameters to encode
*/
public static encodeParameters(pramaters: any) {
Object.keys(pramaters).forEach((key, index) => {
pramaters[key] = encodeURIComponent(pramaters[key]);
});
return pramaters;
}
}
View
@@ -201,7 +201,7 @@ export class AxiosHTTP extends AbstractHTTP {
}
if (allOptions.parameters) {
ret.params = Util.encodeParameters(clonedeep(allOptions.parameters));
ret.params = clonedeep(allOptions.parameters);
}
if (allOptions.data) {
View
@@ -149,7 +149,7 @@ export class GrafanaHTTP extends AbstractHTTP {
}
if (allOptions.parameters && Object.keys(allOptions.parameters).length > 0) {
ret.params = Util.encodeParameters(clonedeep(allOptions.parameters));
ret.params = clonedeep(allOptions.parameters);
}
if (allOptions.data) {
@@ -77,12 +77,12 @@ describe('V1FilterProcessor', () => {
proc.getParameters(filter);
}).toThrow(OnmsError);
});
it('alarm filter: lastEventTime=1976-04-14T00:00:00.000+0000', () => {
it('alarm filter: lastEventTime=1976-04-14T00:00:00.000-0000', () => {
const filter = new Filter();
filter.withOrRestriction(new Restriction('lastEventTime', Comparators.EQ, new Date(198288000000)));
const proc = new V1FilterProcessor();
expect(proc.getParameters(filter)).toMatchObject({
lastEventTime: '1976-04-14T00:00:00.000+0000'
lastEventTime: '1976-04-14T00:00:00.000-0000'
});
});
});
@@ -48,7 +48,7 @@ describe('V2FilterProcessor', () => {
const filter = new Filter();
filter.withOrRestriction(new Restriction('id', Comparators.NOTNULL));
filter.withOrRestriction(new Restriction('ackTime', Comparators.NULL, V2FilterProcessor.NULL_DATE));
expect(toSearch(filter)).toEqual('id!=\u0000,ackTime==1970-01-01T00:00:00.000+0000');
expect(toSearch(filter)).toEqual('id!=\u0000,ackTime==1970-01-01T00:00:00.000-0000');
});
it('alarm filter: id=notnull OR severity="MINOR"', () => {
const filter = new Filter();
@@ -95,14 +95,14 @@ describe('V2FilterProcessor', () => {
);
expect(toSearch(filter)).toEqual('id!=0;(severity==5,uei==*somethingWentWrong)');
});
it('alarm filter: lastEventTime=1976-04-14T00:00:00.000+0000', () => {
const filter = new Filter();
filter.withAndRestriction(new Restriction('lastEventTime', Comparators.EQ, new Date(198288000000)));
expect(toSearch(filter)).toEqual('lastEventTime==1976-04-14T00:00:00.000+0000');
it('alarm filter: lastEventTime=1976-04-14T00:00:00.000-0000', () => {
const filter = new Filter();
filter.withAndRestriction(new Restriction('lastEventTime', Comparators.EQ, new Date(198288000000)));
expect(toSearch(filter)).toEqual('lastEventTime==1976-04-14T00:00:00.000-0000');
});
it('alarm filter: verify null replacement for EQ and NE comparators', () => {
// the filter does not make any sense, but is there to verify that null replacement works correctly
const filter = new Filter<OnmsAlarm>()
const filter = new Filter()
.withAndRestriction(new Restriction('alarmAckTime', Comparators.EQ, 'null'))
.withAndRestriction(new Restriction('alarmAckTime', Comparators.NE, 'null'))
.withAndRestriction(new Restriction('id', Comparators.EQ, 'null'))
@@ -112,8 +112,8 @@ describe('V2FilterProcessor', () => {
{ id: 'alarmAckTime', type: SearchPropertyTypes.TIMESTAMP } as SearchProperty,
]));
expect(toSearch(filter, proc)).toEqual(
'alarmAckTime==1970-01-01T00:00:00.000+0000'
+ ';alarmAckTime!=1970-01-01T00:00:00.000+0000'
'alarmAckTime==1970-01-01T00:00:00.000-0000'
+ ';alarmAckTime!=1970-01-01T00:00:00.000-0000'
+ ';id==\u0000;id!=\u0000');
});
});
@@ -10,7 +10,7 @@ import {Moment} from 'moment';
const moment = require('moment');
/** @hidden */
const ARBITRARY_STRING = '2017-08-08T12:29:56.000+0000';
const ARBITRARY_STRING = '2017-08-08T12:29:56.000-0000';
/** @hidden */
const ARBITRARY_EPOCH = 1502195396000;
@@ -95,15 +95,15 @@ describe('Util.toDateString()', () => {
expect(Util.toDateString(null)).toBeUndefined();
});
it('moment(0)', () => {
expect(Util.toDateString(moment(0))).toEqual('1970-01-01T00:00:00.000+0000');
expect(Util.toDateString(moment(0))).toEqual('1970-01-01T00:00:00.000-0000');
});
it('0', () => {
expect(Util.toDateString(0)).toEqual('1970-01-01T00:00:00.000+0000');
expect(Util.toDateString(0)).toEqual('1970-01-01T00:00:00.000-0000');
});
it('new Date()', () => {
expect(Util.toDateString(new Date(ARBITRARY_EPOCH))).toEqual(ARBITRARY_STRING);
});
it('new Date(0)', () => {
expect(Util.toDateString(new Date(0))).toEqual('1970-01-01T00:00:00.000+0000');
expect(Util.toDateString(new Date(0))).toEqual('1970-01-01T00:00:00.000-0000');
});
});

0 comments on commit abdfc0b

Please sign in to comment.