Skip to content

Instantly share code, notes, and snippets.

View yonatansnir's full-sized avatar

Yonatan Snir yonatansnir

View GitHub Profile
@yonatansnir
yonatansnir / ObjectId.js
Created October 13, 2021 20:18
MongoDB ObjectId class.
class ObjectId {
constructor(id){
if (id)
this._id = id;
else
this._id = this.generateObjectId();
}
createdTime(){
let hexTimestamp = this._id.substring(0, 8)
@yonatansnir
yonatansnir / falsehoods-programming-time-list.md
Created October 12, 2020 14:51 — forked from timvisee/falsehoods-programming-time-list.md
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@yonatansnir
yonatansnir / minutesBetween.js
Created October 11, 2020 11:29
Calculate Minutes between two dates
function minutesBetween(date1, date2){
const minuteInMs = 1000*60;
let diffInMs = Math.abs(date1.getTime() - date2.getTime());
let result = diffInMs / minuteInMs;
return Math.floor(result);
}
@yonatansnir
yonatansnir / daysBetween.js
Last active October 11, 2020 11:28
Calculate Days Between Two Dates.
function daysBetween(date1, date2){
const oneDayInMs = 1000*60*60*24;
let diffInMs = Math.abs(date1.getTime() - date2.getTime())
let result = diffInMs / oneDayInMs;
return Math.floor(result);
}