Timestamps are converted to start of the days and filtered to b unique before calculating streaks

This commit is contained in:
JelenaBarinova
2016-02-09 09:10:18 -08:00
parent 2d33525d43
commit 631c7ea319
6 changed files with 206 additions and 89 deletions

View File

@@ -3,6 +3,7 @@ import moment from 'moment-timezone';
import { dayCount } from '../../../server/utils/date-utils';
let test = require('tape');
const PST = 'America/Los_Angeles';
test('Day count between two epochs (inclusive) calculation', function (t) {
t.plan(7);
@@ -25,18 +26,18 @@ test('Day count between two epochs (inclusive) calculation', function (t) {
t.equal(dayCount([
moment.utc("8/4/2015 1:00", "M/D/YYYY H:mm").valueOf(),
moment.utc("8/3/2015 23:00", "M/D/YYYY H:mm").valueOf()
]), 2, "should return 2 days when the diff is less than 24h but days are different in default timezone UTC");
]), 2, "should return 2 days when the diff is less than 24h but days are different in UTC");
t.equal(dayCount([
moment.utc("8/4/2015 1:00", "M/D/YYYY H:mm").valueOf(),
moment.utc("8/3/2015 23:00", "M/D/YYYY H:mm").valueOf()
], 'America/Los_Angeles'), 1, "should return 1 day when the diff is less than 24h and days are different in UTC, but given 'America/Los_Angeles' timezone");
], PST), 1, "should return 1 day when the diff is less than 24h and days are different in UTC, but given PST");
t.equal(dayCount([
moment.utc("10/27/2015 1:00", "M/D/YYYY H:mm").valueOf(),
moment.utc("5/12/1982 1:00", "M/D/YYYY H:mm").valueOf()
]), 12222, "should return correct count when there is very big period");
t.equal(dayCount([
moment.utc("8/4/2015 2:00", "M/D/YYYY H:mm").valueOf(),
moment.utc("8/3/2015 2:00", "M/D/YYYY H:mm").valueOf()