Skip to content

Commit

Permalink
Merge pull request #330 from javascriptdata/fix-daterange
Browse files Browse the repository at this point in the history
fix data range bug resulting from getting range between same year
  • Loading branch information
steveoni authored Dec 29, 2021
2 parents f76ba3f + 7e8be5e commit 3688db4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion danfojs-node/src/core/date_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export class date_range {
//check if the end year is greater than start year
let start_year = start_date.getFullYear();
let end_year = end_date.getFullYear();
if ((start_year < end_year)){
if ((start_year <= end_year) && (start_date.getMonth() !== end_date.getMonth())){

// end_range = start_range + end_range
if (this.freq == "M"){
end_range = this.month_end(start_date, end_date);
Expand Down
30 changes: 23 additions & 7 deletions danfojs-node/tests/core/date_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ describe("date_range", function(){

// let d = new date_range({"start":'2018-04-24',"end":'2018-04-27'})
// let rslt = [
// '4/24/2018, 12:00:00 AM',
// '4/25/2018, 12:00:00 AM',
// '4/26/2018, 12:00:00 AM',
// '4/27/2018, 12:00:00 AM'
// ]

// '4/24/2018, 1:00:00 AM',
// '4/25/2018, 1:00:00 AM',
// '4/26/2018, 1:00:00 AM',
// '4/27/2018, 1:00:00 AM'
// ]
// assert.deepEqual(d,rslt)


// });
it("Obtain date between start with end not specified, but period and freq specified", function(){

Expand Down Expand Up @@ -90,4 +88,22 @@ describe("date_range", function(){
it("inputing wrong freq offset", function(){
assert.throws(function () { new date_range({ end:'1/1/2018', period:8, freq:"abcm" }); }, Error, 'invalid freq offset abc');
});
// it("Obtain date between start and end specified with different month", function(){

// let d = new date_range({"start":'2018-04-24',"end":'2018-05-27'})
// let rslt = [
// '4/24/2018, 1:00:00 AM',
// '4/25/2018, 1:00:00 AM',
// '4/26/2018, 1:00:00 AM',
// '4/27/2018, 1:00:00 AM',
// '4/28/2018, 1:00:00 AM',
// '4/29/2018, 1:00:00 AM',
// '4/30/2018, 1:00:00 AM',
// '5/1/2018, 1:00:00 AM',
// '5/2/2018, 1:00:00 AM',
// '5/3/2018, 1:00:00 AM',
// '5/27/2018, 1:00:00 AM'
// ]
// assert.deepEqual(d,rslt)
// });
});

0 comments on commit 3688db4

Please sign in to comment.