Skip to content

Instantly share code, notes, and snippets.

@netstart
Last active October 15, 2019 17:33
Show Gist options
  • Save netstart/c92e09730f3675ba8fb33be48520a86d to your computer and use it in GitHub Desktop.
Save netstart/c92e09730f3675ba8fb33be48520a86d to your computer and use it in GitHub Desktop.

Revisions

  1. netstart revised this gist Oct 15, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions date.extensions.ts
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    /**
    * just import, like
    * Import on top of app.module.ts to use across the application
    *
    * import './../shared/utils/date.prototype.extendions';
    * import './shared/utils/date.prototype.extendions';
    */
    declare global {
    interface Date {
  2. netstart revised this gist Oct 15, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion date.extensions.ts
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    /**
    * just import, like
    *
    * import './../shared/utils/date.prototype.extendions.ts';
    * import './../shared/utils/date.prototype.extendions';
    */
    declare global {
    interface Date {
  3. netstart revised this gist Oct 15, 2019. 1 changed file with 13 additions and 2 deletions.
    15 changes: 13 additions & 2 deletions date.extensions.ts
    Original file line number Diff line number Diff line change
    @@ -3,20 +3,28 @@
    *
    * import './../shared/utils/date.prototype.extendions.ts';
    */
    export {};

    declare global {
    interface Date {
    addDays(days: number, useThis?: boolean): Date;

    addSeconds(seconds: number): Date;

    addMinutes(minutes: number): Date;

    addHours(hours: number): Date;

    addMonths(months: number): Date;

    isToday(): boolean;

    clone(): Date;

    isAnotherMonth(date: Date): boolean;

    isWeekend(): boolean;

    isSameDate(date: Date): boolean;

    getStringDate(): string;
    }
    }
    @@ -107,3 +115,6 @@ Date.prototype.getStringDate = function(): string {
    // return this.monthNames[this.getMonth()] + ' ' + this.getDay() + ', ' + this.getFullYear();
    }
    };


    export {};
  4. netstart revised this gist Oct 15, 2019. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions date.extensions.ts
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    /**
    * just import, like
    *
    * import './../shared/utils/date.prototype.extendions.ts';
    */
    export {};

    declare global {
  5. netstart revised this gist Oct 15, 2019. 1 changed file with 13 additions and 18 deletions.
    31 changes: 13 additions & 18 deletions date.extensions.ts
    Original file line number Diff line number Diff line change
    @@ -8,15 +8,10 @@ declare global {
    addHours(hours: number): Date;
    addMonths(months: number): Date;
    isToday(): boolean;

    clone(): Date;

    isAnotherMonth(date: Date): boolean;

    isWeekend(): boolean;

    isSameDate(date: Date): boolean;

    getStringDate(): string;
    }
    }
    @@ -87,23 +82,23 @@ Date.prototype.isSameDate = function(date: Date): boolean {
    return date && this.getFullYear() === date.getFullYear() && this.getMonth() === date.getMonth() && this.getDate() === date.getDate();
    };

    Date.prototype.getStringDate = function(): String {
    //Month names in Brazilian Portuguese
    let monthNames = ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'];
    //Month names in English
    //let monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    let today = new Date();
    if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay()) {
    Date.prototype.getStringDate = function(): string {
    // Month names in Brazilian Portuguese
    const monthNames = ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'];
    // Month names in English
    // let monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    const today = new Date();
    if (this.getMonth() === today.getMonth() && this.getDay() === today.getDay()) {
    return 'Hoje';
    //return "Today";
    } else if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay() + 1) {
    // return "Today";
    } else if (this.getMonth() === today.getMonth() && this.getDay() === today.getDay() + 1) {
    return 'Amanhã';
    //return "Tomorrow";
    } else if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay() - 1) {
    // return "Tomorrow";
    } else if (this.getMonth() === today.getMonth() && this.getDay() === today.getDay() - 1) {
    return 'Ontem';
    //return "Yesterday";
    // return "Yesterday";
    } else {
    return this.getDay() + ' de ' + this.monthNames[this.getMonth()] + ' de ' + this.getFullYear();
    //return this.monthNames[this.getMonth()] + ' ' + this.getDay() + ', ' + this.getFullYear();
    // return this.monthNames[this.getMonth()] + ' ' + this.getDay() + ', ' + this.getFullYear();
    }
    };
  6. netstart revised this gist Oct 15, 2019. 1 changed file with 86 additions and 77 deletions.
    163 changes: 86 additions & 77 deletions date.extensions.ts
    Original file line number Diff line number Diff line change
    @@ -1,100 +1,109 @@
    export {}
    export {};

    declare global {
    interface Date {
    addDays(days: number, useThis?: boolean): Date;
    isToday(): boolean;
    clone(): Date;
    isAnotherMonth(date: Date): boolean;
    isWeekend(): boolean;
    isSameDate(date: Date): boolean;
    getStringDate(): String;
    }
    }
    interface Date {
    addDays(days: number, useThis?: boolean): Date;
    addSeconds(seconds: number): Date;
    addMinutes(minutes: number): Date;
    addHours(hours: number): Date;
    addMonths(months: number): Date;
    isToday(): boolean;

    Date.prototype.addDays = function (days: number): Date {
    if (!days) return this;
    let date = this;
    date.setDate(date.getDate() + days);
    clone(): Date;

    return date;
    };
    Date.prototype.addSeconds = function (num) {
    var value = this.valueOf();
    value += 1000 * num;
    return new Date(value);
    }
    isAnotherMonth(date: Date): boolean;

    Date.prototype.addMinutes = function (num) {
    var value = this.valueOf();
    value += 60000 * num;
    return new Date(value);
    }
    isWeekend(): boolean;

    Date.prototype.addHours = function (num) {
    var value = this.valueOf();
    value += 3600000 * num;
    return new Date(value);
    isSameDate(date: Date): boolean;

    getStringDate(): string;
    }
    }

    Date.prototype.addMonths = function (num) {
    var value = new Date(this.valueOf());
    Date.prototype.addDays = function(days: number): Date {
    if (!days) {
    return this;
    }
    this.setDate(this.getDate() + days);
    return this;
    };

    Date.prototype.addSeconds = function(seconds: number) {
    let value = this.valueOf();
    value += 1000 * seconds;
    return new Date(value);
    };

    Date.prototype.addMinutes = function(minutes: number) {
    let value = this.valueOf();
    value += 60000 * minutes;
    return new Date(value);
    };

    var mo = this.getMonth();
    var yr = this.getYear();
    Date.prototype.addHours = function(hours: number) {
    let value = this.valueOf();
    value += 3600000 * hours;
    return new Date(value);
    };

    mo = (mo + num) % 12;
    if (0 > mo) {
    yr += (this.getMonth() + num - mo - 12) / 12;
    mo += 12;
    }
    else
    yr += ((this.getMonth() + num - mo) / 12);
    Date.prototype.addMonths = function(months: number) {
    const value = new Date(this.valueOf());

    value.setMonth(mo);
    value.setYear(yr);
    return value;
    }
    let mo = this.getMonth();
    let yr = this.getYear();

    Date.prototype.isToday = function (): boolean{
    let today = new Date();
    return this.isSameDate(today);
    mo = (mo + months) % 12;
    if (0 > mo) {
    yr += (this.getMonth() + months - mo - 12) / 12;
    mo += 12;
    } else {
    yr += ((this.getMonth() + months - mo) / 12);
    }

    value.setMonth(mo);
    value.setFullYear(yr);
    return value;
    };

    Date.prototype.clone = function (): Date{
    return new Date(+this);
    Date.prototype.isToday = function(): boolean {
    const today = new Date();
    return this.isSameDate(today);
    };

    Date.prototype.isAnotherMonth = function (date: Date): boolean {
    return date && this.getMonth() !== date.getMonth();
    Date.prototype.clone = function(): Date {
    return new Date(+this);
    };

    Date.prototype.isWeekend = function (): boolean {
    return this.getDay() === 0 || this.getDay() === 6;
    Date.prototype.isAnotherMonth = function(date: Date): boolean {
    return date && this.getMonth() !== date.getMonth();
    };

    Date.prototype.isSameDate = function (date: Date): boolean {
    return date && this.getFullYear() === date.getFullYear() && this.getMonth() === date.getMonth() && this.getDate() === date.getDate();
    Date.prototype.isWeekend = function(): boolean {
    return this.getDay() === 0 || this.getDay() === 6;
    };

    Date.prototype.getStringDate = function (): String {
    //Month names in Brazilian Portuguese
    let monthNames = ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'];
    //Month names in English
    //let monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    let today = new Date();
    if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay()) {
    return "Hoje";
    //return "Today";
    } else if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay() + 1) {
    return "Amanhã";
    //return "Tomorrow";
    } else if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay() - 1) {
    return "Ontem";
    //return "Yesterday";
    } else {
    return this.getDay() + ' de ' + this.monthNames[this.getMonth()] + ' de ' + this.getFullYear();
    //return this.monthNames[this.getMonth()] + ' ' + this.getDay() + ', ' + this.getFullYear();
    }
    }
    Date.prototype.isSameDate = function(date: Date): boolean {
    return date && this.getFullYear() === date.getFullYear() && this.getMonth() === date.getMonth() && this.getDate() === date.getDate();
    };

    Date.prototype.getStringDate = function(): String {
    //Month names in Brazilian Portuguese
    let monthNames = ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'];
    //Month names in English
    //let monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    let today = new Date();
    if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay()) {
    return 'Hoje';
    //return "Today";
    } else if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay() + 1) {
    return 'Amanhã';
    //return "Tomorrow";
    } else if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay() - 1) {
    return 'Ontem';
    //return "Yesterday";
    } else {
    return this.getDay() + ' de ' + this.monthNames[this.getMonth()] + ' de ' + this.getFullYear();
    //return this.monthNames[this.getMonth()] + ' ' + this.getDay() + ', ' + this.getFullYear();
    }
    };
  7. netstart revised this gist Oct 15, 2019. 1 changed file with 38 additions and 1 deletion.
    39 changes: 38 additions & 1 deletion date.extensions.ts
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,42 @@ Date.prototype.addDays = function (days: number): Date {

    return date;
    };
    Date.prototype.addSeconds = function (num) {
    var value = this.valueOf();
    value += 1000 * num;
    return new Date(value);
    }

    Date.prototype.addMinutes = function (num) {
    var value = this.valueOf();
    value += 60000 * num;
    return new Date(value);
    }

    Date.prototype.addHours = function (num) {
    var value = this.valueOf();
    value += 3600000 * num;
    return new Date(value);
    }

    Date.prototype.addMonths = function (num) {
    var value = new Date(this.valueOf());

    var mo = this.getMonth();
    var yr = this.getYear();

    mo = (mo + num) % 12;
    if (0 > mo) {
    yr += (this.getMonth() + num - mo - 12) / 12;
    mo += 12;
    }
    else
    yr += ((this.getMonth() + num - mo) / 12);

    value.setMonth(mo);
    value.setYear(yr);
    return value;
    }

    Date.prototype.isToday = function (): boolean{
    let today = new Date();
    @@ -60,4 +96,5 @@ Date.prototype.getStringDate = function (): String {
    return this.getDay() + ' de ' + this.monthNames[this.getMonth()] + ' de ' + this.getFullYear();
    //return this.monthNames[this.getMonth()] + ' ' + this.getDay() + ', ' + this.getFullYear();
    }
    }
    }

  8. netstart created this gist Oct 15, 2019.
    63 changes: 63 additions & 0 deletions date.extensions.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    export {}

    declare global {
    interface Date {
    addDays(days: number, useThis?: boolean): Date;
    isToday(): boolean;
    clone(): Date;
    isAnotherMonth(date: Date): boolean;
    isWeekend(): boolean;
    isSameDate(date: Date): boolean;
    getStringDate(): String;
    }
    }

    Date.prototype.addDays = function (days: number): Date {
    if (!days) return this;
    let date = this;
    date.setDate(date.getDate() + days);

    return date;
    };

    Date.prototype.isToday = function (): boolean{
    let today = new Date();
    return this.isSameDate(today);
    };

    Date.prototype.clone = function (): Date{
    return new Date(+this);
    };

    Date.prototype.isAnotherMonth = function (date: Date): boolean {
    return date && this.getMonth() !== date.getMonth();
    };

    Date.prototype.isWeekend = function (): boolean {
    return this.getDay() === 0 || this.getDay() === 6;
    };

    Date.prototype.isSameDate = function (date: Date): boolean {
    return date && this.getFullYear() === date.getFullYear() && this.getMonth() === date.getMonth() && this.getDate() === date.getDate();
    };

    Date.prototype.getStringDate = function (): String {
    //Month names in Brazilian Portuguese
    let monthNames = ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'];
    //Month names in English
    //let monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    let today = new Date();
    if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay()) {
    return "Hoje";
    //return "Today";
    } else if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay() + 1) {
    return "Amanhã";
    //return "Tomorrow";
    } else if (this.getMonth() == today.getMonth() && this.getDay() == today.getDay() - 1) {
    return "Ontem";
    //return "Yesterday";
    } else {
    return this.getDay() + ' de ' + this.monthNames[this.getMonth()] + ' de ' + this.getFullYear();
    //return this.monthNames[this.getMonth()] + ' ' + this.getDay() + ', ' + this.getFullYear();
    }
    }