Sort by date [default]

Will sort descending by the date when the task was added
Use the reverse flag or function for ascending results
500862
function sortByDate(a, b) {
    return new Date(a.added).getTime() - new Date(b.added).getTime();
  }
1128909
private DateTime providedOrDefaultFromValue(DateTime from, DateTime to,
			AggregateCounterResolution resolution) {
		if (from != null) {
			return from;
		}
		switch (resolution) {
		case minute:
			return to.minusMinutes(59);
		case hour:
			return to.minusHours(23);
		case day:
			return to.minusDays(6);
		case month:
			return to.minusMonths(11);
		case year:
			return to.minusYears(4);
		default:
			throw new IllegalStateException(
					"Shouldn't happen. Unhandled resolution: " + resolution);
		}
	}
868909
function(locationsarray) {
			this.writeDebug('sortDate',arguments);
			var property = (this.settings.sortBy.hasOwnProperty('prop') && typeof this.settings.sortBy.prop !== 'undefined') ?  this.settings.sortBy.prop : 'date';

			if (this.settings.sortBy.hasOwnProperty('order') && this.settings.sortBy.order.toString() === 'desc') {
				locationsarray.sort(function (a, b) {
					return new Date(b[property]).getTime() - new Date(a[property]).getTime();
				});
			} else {
				locationsarray.sort(function (a, b) {
					return new Date(a[property]).getTime() - new Date(b[property]).getTime();
				});
			}
		}
1327615
private void updateDates(Task parentTask)
   {
      if (parentTask.hasChildTasks())
      {
         int finished = 0;
         Date startDate = parentTask.getStart();
         Date finishDate = parentTask.getFinish();
         Date actualStartDate = parentTask.getActualStart();
         Date actualFinishDate = parentTask.getActualFinish();
         Date earlyStartDate = parentTask.getEarlyStart();
         Date earlyFinishDate = parentTask.getEarlyFinish();
         Date lateStartDate = parentTask.getLateStart();
         Date lateFinishDate = parentTask.getLateFinish();

         for (Task task : parentTask.getChildTasks())
         {
            updateDates(task);

            startDate = DateHelper.min(startDate, task.getStart());
            finishDate = DateHelper.max(finishDate, task.getFinish());
            actualStartDate = DateHelper.min(actualStartDate, task.getActualStart());
            actualFinishDate = DateHelper.max(actualFinishDate, task.getActualFinish());
            earlyStartDate = DateHelper.min(earlyStartDate, task.getEarlyStart());
            earlyFinishDate = DateHelper.max(earlyFinishDate, task.getEarlyFinish());
            lateStartDate = DateHelper.min(lateStartDate, task.getLateStart());
            lateFinishDate = DateHelper.max(lateFinishDate, task.getLateFinish());

            if (task.getActualFinish() != null)
            {
               ++finished;
            }
         }

         parentTask.setStart(startDate);
         parentTask.setFinish(finishDate);
         parentTask.setActualStart(actualStartDate);
         parentTask.setEarlyStart(earlyStartDate);
         parentTask.setEarlyFinish(earlyFinishDate);
         parentTask.setLateStart(lateStartDate);
         parentTask.setLateFinish(lateFinishDate);

         //
         // Only if all child tasks have actual finish dates do we
         // set the actual finish date on the parent task.
         //
         if (finished == parentTask.getChildTasks().size())
         {
            parentTask.setActualFinish(actualFinishDate);
         }
      }
   }
617093
function addTask(taskData, subTaskData) {
			var subTaskList,
				parsedData,
				subTask = false;

			if(taskData !== undefined) {
				if(parseInt(taskData,10) > -1) {
					subTaskList = this.getTaskByID(parseInt(taskData,10)).subTasks;

					parsedData = this.parseInputData(subTaskData);
					subTask = true;
				}
				else {
					parsedData = this.parseInputData(taskData);
				}


				var newTask = _.clone(defaultTask)
				_.extend(newTask, parsedData);

				newTask.dateAdded = Date.now();
				newTask.id = largestID + 1;
				newTask.subTask = subTask;

				this.tasks.unshift( newTask );

				if(subTask) {
					subTaskList.push(newTask.id);
				}

				console.log('Added:');
				return newTask;
			}
			else {
				console.log('no task name given');
				return false;
			}

		}
301656
function filterDate({
  data,
  value,
  disabledArr,
  minDate,
  maxDate,
  oldData = {},
  props,
  columns,
}) {
  const disabledArrNew = parseDisabledArr(disabledArr);
  if (columns[0] === 'Y') {
    const year = value[0].value;
    let month;
    let yearData = data[0];
    let monthData;
    if (columns.length >= 2) {
      monthData = getMonthsByYear({ year, minDate, maxDate }).map(item => ({
        value: item.value,
        text: `${addZero(item.text)}${locale[props.locale].surfix.M}`,
      }));
      month = value[1].value;
    }
    let dayData;
    if (columns.length >= 3) {
      dayData = getDaysByMonth({
        year, month, minDate, maxDate,
      });
    }
    if (disabledArrNew.startEnd || disabledArrNew.minTime || disabledArrNew.maxTime) {
      if (oldData.yearData) {
        ({ yearData } = oldData);
      } else {
        yearData = filterYear(yearData, { disabledDateObj: disabledArrNew, minDate, maxDate });
      }
      if (monthData) {
        if (oldData.monthData) {
          ({ monthData } = oldData);
        } else {
          const monthArr = filterMonth(monthData, year, disabledArrNew);
          monthData = monthArr.length ? monthArr : monthData;
        }
      }

      if (dayData) {
        const dayArr = filterDay(dayData, year, month, disabledArrNew);
        dayData = dayArr.length ? dayArr : dayData;
        const unit = locale[props.locale].surfix.D;
        dayData = dayData.map(item => ({
          ...item,
          text: addZero(item.text) + (unit || ''),
        }));
      }
    }
    if (disabledArrNew.minTime >= disabledArrNew.maxTime) {
      warn('Datetime: Please check your disabledDate props');
      return [];
    }
    if (!yearData.length) {
      return [];
    }
    const outArr = [yearData];
    if (monthData) {
      outArr.push(monthData);
      if (dayData) {
        outArr.push(dayData);
      }
    }

    if (data[3]) {
      outArr.push(data[3]);
    }
    return outArr;
  }
  if (['YMD', 'YMDW'].indexOf(columns[0]) !== -1) {
    const newData = [...data];
    newData[0] = filterYMDDay(newData[0], disabledArr);

    return newData;
  }
  return data;
}
908744
function () {
		var self = this,
			dates = Object.keys(this.parse_tree),
			lines = [];
		
		dates.sort();
		dates.forEach(function (dy, i) {
			var times = Object.keys(self.parse_tree[dy]);
			lines.push(dy);
			times.sort();
			times.forEach(function (tm) {
				var tags = "", maps = "", notes = "", rec;
				
				rec = self.parse_tree[dy][tm];
				if (typeof rec === "string") {
					notes = rec;
				} else {
					if (typeof rec.map !== "undefined" &&
							rec.map !== false) {
						maps = [
							rec.map.project_name,
							rec.map.task
						].join(", ") + "; ";
					}
					if (typeof rec.tags !== "undefined" &&
							rec.tags !== false) {
						tags = rec.tags.join(", ") + "; ";
					}
					if (typeof rec.notes !== "undefined") {
						notes = rec.notes;
					}
				}

				lines.push([
					tm,
					"; ",
					tags,
					maps,
					notes
				].join(""));
			});
		});
		
		return lines.join("\n\n");
	}
83697
def is_closest_date_parameter(task, param_name):
    
    for name, obj in task.get_params():
        if name == param_name:
            return hasattr(obj, 'use_closest_date')
    return False
43071
def _apply_sort(cursor, sort_by, sort_direction):
        
        if sort_direction is not None and sort_direction.lower() == "desc":
            sort = pymongo.DESCENDING
        else:
            sort = pymongo.ASCENDING
        return cursor.sort(sort_by, sort)
57917
function(inst, date, defaultDate) {
		var offsetNumeric = function(offset) {
				var date = new Date();
				date.setDate(date.getDate() + offset);
				return date;
			},
			offsetString = function(offset) {
				try {
					return $.datepicker.parseDate($.datepicker._get(inst, "dateFormat"),
						offset, $.datepicker._getFormatConfig(inst));
				}
				catch (e) {
					// Ignore
				}

				var date = (offset.toLowerCase().match(/^c/) ?
					$.datepicker._getDate(inst) : null) || new Date(),
					year = date.getFullYear(),
					month = date.getMonth(),
					day = date.getDate(),
					pattern = /([+\-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g,
					matches = pattern.exec(offset);

				while (matches) {
					switch (matches[2] || "d") {
						case "d" : case "D" :
							day += parseInt(matches[1],10); break;
						case "w" : case "W" :
							day += parseInt(matches[1],10) * 7; break;
						case "m" : case "M" :
							month += parseInt(matches[1],10);
							day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
							break;
						case "y": case "Y" :
							year += parseInt(matches[1],10);
							day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
							break;
					}
					matches = pattern.exec(offset);
				}
				return new Date(year, month, day);
			},
			newDate = (date == null || date === "" ? defaultDate : (typeof date === "string" ? offsetString(date) :
				(typeof date === "number" ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : new Date(date.getTime()))));

		newDate = (newDate && newDate.toString() === "Invalid Date" ? defaultDate : newDate);
		if (newDate) {
			newDate.setHours(0);
			newDate.setMinutes(0);
			newDate.setSeconds(0);
			newDate.setMilliseconds(0);
		}
		return this._daylightSavingAdjust(newDate);
	}
1133514
def include? date
      result = false
      walk { |elements|
        break result = true if elements.include? date 
      }

      return result if !result || date.class == Date || times.nil?

      times.include? date
    end
817470
def sort_func(self, entry):
        
        key = entry[self.sort]

        if self.sort in FLOAT_ATTRIBUTES and not isinstance(key, float):
            return 0  # If value is 'n/a' string
        elif self.sort == 'time':
            return convert_time(key)
        elif self.sort == 'date':
            return convert_date(key)

        return key
1110366
def sort_by_speedup(self, reverse=True):
        """"""
        self._confs.sort(key=lambda c: c.speedup, reverse=reverse)
        return self
1283254
function sortPosts (posts) {
  return Object.keys(posts).map(function (post) { return posts[post]; })
    .sort(function (a,b) {
      if ( a.date < b.date ) return 1;
      if ( a.date > b.date ) return -1;
      return 0;
    });
}
636136
function(date) {
        var minDate = this.cfg.getProperty(DEF_CFG.MINDATE.key),
            maxDate = this.cfg.getProperty(DEF_CFG.MAXDATE.key),
            dm = DateMath;
        
        if (minDate) {
            minDate = dm.clearTime(minDate);
        } 
        if (maxDate) {
            maxDate = dm.clearTime(maxDate);
        }
    
        var clearedDate = new Date(date.getTime());
        clearedDate = dm.clearTime(clearedDate);
    
        return ((minDate && clearedDate.getTime() < minDate.getTime()) || (maxDate && clearedDate.getTime() > maxDate.getTime()));
    }
73591
function() {

		var time = new Date().getTime(),
			i = 0,
			count = this._active_tasks.length,
			task,
			active_tasks = [];

		for (; i < count; i++) {

			task = this._active_tasks[i];

			if (task.isRunning()) {
				task.onTimer(time);
				// note: at this moment task may be already off, but it's not checked - to save processor resources.
				active_tasks.push(task);
			}

		}

		if (!active_tasks.length) {

			this.is_running = false;

		}

		this._active_tasks = active_tasks;

	}
671128
private void updateDates(Task parentTask)
   {
      if (parentTask.hasChildTasks())
      {
         int finished = 0;
         Date plannedStartDate = parentTask.getStart();
         Date plannedFinishDate = parentTask.getFinish();
         Date actualStartDate = parentTask.getActualStart();
         Date actualFinishDate = parentTask.getActualFinish();
         Date earlyStartDate = parentTask.getEarlyStart();
         Date earlyFinishDate = parentTask.getEarlyFinish();
         Date lateStartDate = parentTask.getLateStart();
         Date lateFinishDate = parentTask.getLateFinish();

         for (Task task : parentTask.getChildTasks())
         {
            updateDates(task);

            plannedStartDate = DateHelper.min(plannedStartDate, task.getStart());
            plannedFinishDate = DateHelper.max(plannedFinishDate, task.getFinish());
            actualStartDate = DateHelper.min(actualStartDate, task.getActualStart());
            actualFinishDate = DateHelper.max(actualFinishDate, task.getActualFinish());
            earlyStartDate = DateHelper.min(earlyStartDate, task.getEarlyStart());
            earlyFinishDate = DateHelper.max(earlyFinishDate, task.getEarlyFinish());
            lateStartDate = DateHelper.min(lateStartDate, task.getLateStart());
            lateFinishDate = DateHelper.max(lateFinishDate, task.getLateFinish());

            if (task.getActualFinish() != null)
            {
               ++finished;
            }
         }

         parentTask.setStart(plannedStartDate);
         parentTask.setFinish(plannedFinishDate);
         parentTask.setActualStart(actualStartDate);
         parentTask.setEarlyStart(earlyStartDate);
         parentTask.setEarlyFinish(earlyFinishDate);
         parentTask.setLateStart(lateStartDate);
         parentTask.setLateFinish(lateFinishDate);

         //
         // Only if all child tasks have actual finish dates do we
         // set the actual finish date on the parent task.
         //
         if (finished == parentTask.getChildTasks().size())
         {
            parentTask.setActualFinish(actualFinishDate);
         }

         Duration duration = null;
         if (plannedStartDate != null && plannedFinishDate != null)
         {
            duration = m_projectFile.getDefaultCalendar().getWork(plannedStartDate, plannedFinishDate, TimeUnit.DAYS);
            parentTask.setDuration(duration);
         }
      }
   }