iamkun / iamkun/dayjs

Native support for highly desirable date times

Open
#1,825 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.8k
PR merge metrics
No merged PRs in 30d

Description

**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.

```js

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:

```json
{
"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)]

Contributor guide

Open the contributing guide

Research direction

No source file or test is named. Start by reviewing Day.js's existing API and the date-range examples in the issue, then clarify the intended method names, supported periods, boundaries, and previous-period behavior; done means those decisions are implemented and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.