Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native support for highly desirable date times #1825

Open
suchislife801 opened this issue Mar 10, 2022 · 0 comments
Open

Native support for highly desirable date times #1825

suchislife801 opened this issue Mar 10, 2022 · 0 comments

Comments

@suchislife801
Copy link

suchislife801 commented Mar 10, 2022

Describe the bug
A clear and concise description of what the bug is.

I find myself using these specific date times whenever I code a date time base app. Day.JS doesn't seem to have these although it's easy to implement.

Expected behavior
A clear and concise description of what you expected to happen.

Below is an object that contains all of these special date time stamps. It would be sweet if DayJS just had these available as read only methods.

return {

  current: {
    day: {
      start: dayjs().format('YYYY-MM-DD 00:00:01'),
      end: dayjs().format('YYYY-MM-DD 23:59:59'),
    },
    week: {
      start: dayjs().day(1).format('YYYY-MM-DD 00:00:01'),
      end: dayjs().day(1).add(6, 'day').format('YYYY-MM-DD 23:59:59'),
    },
    month: {
      start: dayjs().date(1).format('YYYY-MM-DD 00:00:01'),
      end: dayjs().date(dayjs().daysInMonth()).format('YYYY-MM-DD 23:59:59'),
    },
    quarter: {
      q1: {
        start: dayjs(new Date(new Date().getFullYear(), 0, 1)).format('YYYY-MM-DD 00:00:01'),
        end: dayjs(new Date(new Date().getFullYear(), 0, 1)).add(3, 'month').subtract(1, 'day').format('YYYY-MM-DD 23:59:59'),
      },
      q2: {
        start: dayjs(new Date(new Date().getFullYear(), 0, 1)).add(3, 'month').format('YYYY-MM-DD 00:00:01'),
        end: dayjs(new Date(new Date().getFullYear(), 0, 1)).add(6, 'month').subtract(1, 'day').format('YYYY-MM-DD 23:59:59'),
      },
      q3: {
        start: dayjs(new Date(new Date().getFullYear(), 0, 1)).add(6, 'month').format('YYYY-MM-DD 00:00:01'),
        end: dayjs(new Date(new Date().getFullYear(), 0, 1)).add(9, 'month').subtract(1, 'day').format('YYYY-MM-DD 23:59:59'),
      },
      q4: {
        start: dayjs(new Date(new Date().getFullYear(), 0, 1)).add(9, 'month').format('YYYY-MM-DD 00:00:01'),
        end: dayjs(new Date(new Date().getFullYear(), 0, 1)).add(12, 'month').subtract(1, 'day').format('YYYY-MM-DD 23:59:59'),
      },
    },
    year: {
      start: dayjs(new Date(new Date().getFullYear(), 0, 1)).format('YYYY-MM-DD 00:00:01'),
      end: dayjs(new Date(new Date().getFullYear(), 0, 1)).add(12, 'month').subtract(1, 'day').format('YYYY-MM-DD 00:00:01'),
    },

  },

  previous: {
    day: {
      start: dayjs().subtract(1, 'day').format('YYYY-MM-DD 00:00:01'),
      end: dayjs().subtract(1, 'day').format('YYYY-MM-DD 23:59:59'),
    },
    week: {
      start: dayjs().day(1).subtract(7, 'day').format('YYYY-MM-DD 00:00:01'),
      end: dayjs().day(1).subtract(1, 'day').format('YYYY-MM-DD 23:59:59'),
    },
    month: {
      start: dayjs().date(1).subtract(1, 'month').format('YYYY-MM-DD 00:00:01'),
      end: dayjs().date(dayjs().daysInMonth()).subtract(1, 'month').format('YYYY-MM-DD 23:59:59'),
    },
    quarter: {
      q1: {
        start: dayjs(new Date(new Date().getFullYear(), 0, 1)).subtract(1, 'year').format('YYYY-MM-DD 00:00:01'),
        end: dayjs(new Date(new Date().getFullYear(), 0, 1)).subtract(1, 'year').add(3, 'month').subtract(1, 'day').format('YYYY-MM-DD 23:59:59'),
      },
      q2: {
        start: dayjs(new Date(new Date().getFullYear(), 0, 1)).subtract(1, 'year').add(3, 'month').format('YYYY-MM-DD 00:00:01'),
        end: dayjs(new Date(new Date().getFullYear(), 0, 1)).subtract(1, 'year').add(6, 'month').subtract(1, 'day').format('YYYY-MM-DD 23:59:59'),
      },
      q3: {
        start: dayjs(new Date(new Date().getFullYear(), 0, 1)).subtract(1, 'year').add(6, 'month').format('YYYY-MM-DD 00:00:01'),
        end: dayjs(new Date(new Date().getFullYear(), 0, 1)).subtract(1, 'year').add(9, 'month').subtract(1, 'day').format('YYYY-MM-DD 23:59:59'),
      },
      q4: {
        start: dayjs(new Date(new Date().getFullYear(), 0, 1)).subtract(1, 'year').add(9, 'month').format('YYYY-MM-DD 00:00:01'),
        end: dayjs(new Date(new Date().getFullYear(), 0, 1)).subtract(1, 'year').add(12, 'month').subtract(1, 'day').format('YYYY-MM-DD 23:59:59'),
      },
    },
    year: {
      start: dayjs(new Date(new Date().getFullYear(), 0, 1)).subtract(1, 'year').format('YYYY-MM-DD 00:00:01'),
      end: dayjs(new Date(new Date().getFullYear(), 12, 0)).subtract(1, 'year').format('YYYY-MM-DD 23:59:59'),
    },

  },

}

Output as of 03/10/2022:

{
  "current": {
    "day": {
      "start": "2022-03-10 00:00:01",
      "end": "2022-03-10 23:59:59"
    },
    "week": {
      "start": "2022-03-07 00:00:01",
      "end": "2022-03-13 23:59:59"
    },
    "month": {
      "start": "2022-03-01 00:00:01",
      "end": "2022-03-31 23:59:59"
    },
    "quarter": {
      "q1": {
        "start": "2022-01-01 00:00:01",
        "end": "2022-03-31 23:59:59"
      },
      "q2": {
        "start": "2022-04-01 00:00:01",
        "end": "2022-06-30 23:59:59"
      },
      "q3": {
        "start": "2022-07-01 00:00:01",
        "end": "2022-09-30 23:59:59"
      },
      "q4": {
        "start": "2022-10-01 00:00:01",
        "end": "2022-12-31 23:59:59"
      }
    },
    "year": {
      "start": "2022-01-01 00:00:01",
      "end": "2022-12-31 00:00:01"
    }
  },
  "previous": {
    "day": {
      "start": "2022-03-09 00:00:01",
      "end": "2022-03-09 23:59:59"
    },
    "week": {
      "start": "2022-02-28 00:00:01",
      "end": "2022-03-06 23:59:59"
    },
    "month": {
      "start": "2022-02-01 00:00:01",
      "end": "2022-02-28 23:59:59"
    },
    "quarter": {
      "q1": {
        "start": "2021-01-01 00:00:01",
        "end": "2021-03-31 23:59:59"
      },
      "q2": {
        "start": "2021-04-01 00:00:01",
        "end": "2021-06-30 23:59:59"
      },
      "q3": {
        "start": "2021-07-01 00:00:01",
        "end": "2021-09-30 23:59:59"
      },
      "q4": {
        "start": "2021-10-01 00:00:01",
        "end": "2021-12-31 23:59:59"
      }
    },
    "year": {
      "start": "2021-01-01 00:00:01",
      "end": "2021-12-31 23:59:59"
    }
  }
}

Information

  • Day.js Version [e.g. v1.0.0]
  • OS: [e.g. iOS]
  • Browser [e.g. chrome 62]
  • Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant