<commit_before>var deserialize      = require('../util/deserialize'),
    end              = require('../actions/end'),
    moment           = require('moment'),
    preHandleOptions = require('./common/prehandleOptions');

module.exports = function listTasks(options, output) {
    "use strict";
    var context = preHandleOptions(options);
    var from, to;

    // handle option flags and set 'from' & 'to'
    if (options.yesterday) {
        from = moment().subtract(1, 'day').startOf('day');
        to = moment().subtract(1, 'day').endOf('day');
    }
    if (options.week) {
        from = moment().startOf('week');
        to = moment().endOf('week');
    }
    if (options.month) {
        from = moment().startOf('month');
        to = moment().endOf('month');
    }

    // build query
    var query;
    if (options.all) {
        query = {start: {$exists: true}};
    } else {
        from = from || options.from || moment().startOf('day');
        to = to || options.to || moment().endOf('day');
        query = {$and: [{start: {$gt: from.toDate()}}, {start: {$lt: to.toDate()}}]}
    }

    if (options.search){
        var regex = new RegExp(options.search);
        query.$and.push({$or: [{note: {$regex: regex}}, {task: {$regex: regex}}, {project: {$regex: regex}}] });
    }

    var db = context.db;
    db.find(query)
        .sort({start: 1})
        .exec(function (err, tasks) {
            if (err) {
                return output(err);
            }

            tasks = tasks.map(function (task) {
                return deserialize(task);
            });

            // output
            output(null, context, tasks);
        });
};

<commit_msg>fix bug when using list command with search query and --all flag<commit_after>var deserialize      = require('../util/deserialize'),
    end              = require('../actions/end'),
    moment           = require('moment'),
    preHandleOptions = require('./common/prehandleOptions');

module.exports = function listTasks(options, output) {
    "use strict";
    var context = preHandleOptions(options);
    var from, to;

    // handle option flags and set 'from' & 'to'
    if (options.yesterday) {
        from = moment().subtract(1, 'day').startOf('day');
        to = moment().subtract(1, 'day').endOf('day');
    }
    if (options.week) {
        from = moment().startOf('week');
        to = moment().endOf('week');
    }
    if (options.month) {
        from = moment().startOf('month');
        to = moment().endOf('month');
    }

    // build query
    var query;
    if (options.all) {
        query = {start: {$exists: true}};
    } else {
        from = from || options.from || moment().startOf('day');
        to = to || options.to || moment().endOf('day');
        query = {$and: [{start: {$gt: from.toDate()}}, {start: {$lt: to.toDate()}}]}
    }

    if (options.search) {
        var regex = new RegExp(options.search);
        if (!query.$and) {
            query = {$and: [query]};
        }
        query.$and.push({$or: [{note: {$regex: regex}}, {task: {$regex: regex}}, {project: {$regex: regex}}]});
    }

    var db = context.db;
    db.find(query)
        .sort({start: 1})
        .exec(function (err, tasks) {
            if (err) {
                return output(err);
            }

            tasks = tasks.map(function (task) {
                return deserialize(task);
            });

            // output
            output(null, context, tasks);
        });
};


{'fraction_non_alphanumeric': 0.18309859154929578, 'fraction_numerical': 0.0017246335153779822, 'mean_word_length': 2.007778738115817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1736748', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1029, 'n_words': 242}