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

Add Request day().add(object) #575

Closed
hijazikaram opened this issue Apr 17, 2019 · 25 comments
Closed

Add Request day().add(object) #575

hijazikaram opened this issue Apr 17, 2019 · 25 comments

Comments

@hijazikaram
Copy link

hijazikaram commented Apr 17, 2019

Describe the bug
Hi,

I kind of like this project, I'd like to use it to add an object instead of just using add(value: number, unit: string). I was using moment before but im moving into using dayjs because its way smaller.

Expected behavior
const maxTimestamp = moment(this.endDate.value.valueOf()) .utc() .startOf('day'); maxTimestamp.add({ hours: minTime.slice(0, 2), minutes: minTime.slice(3, 5) });
Trying to switch that into:
const maxTimestamp = day(this.endDate.value.valueOf()) .utc() .startOf('day'); maxTimestamp.add({ hours: minTime.slice(0, 2), minutes: minTime.slice(3, 5) });
Information

  • Day.js Version [e.g. v1.0.0]
  • OS: [e.g. iOS]
  • Browser [e.g. chrome 62]
@hijazikaram hijazikaram changed the title moment().add({}) Add Request day().add(object) Apr 17, 2019
@hijazikaram hijazikaram reopened this Apr 17, 2019
@ghost
Copy link

ghost commented Apr 17, 2019

Trying to switch that into:

Exact the same with above line?

@hijazikaram
Copy link
Author

hijazikaram commented Apr 17, 2019

@xxyuk the first one im using moment, trying to use dayjs instead

@iamkun
Copy link
Owner

iamkun commented Apr 18, 2019

Yes, we could support this as a plugin to add a time object.

@hijazikaram
Copy link
Author

Having the same issue with this
startDateTime = startDateTime.set({ hour: startTime.get('hours'), minutes: startTime.get('minutes'), seconds: startTime.get('seconds') }); endDateTime = endDateTime.set({ hour: endTime.get('hours'), minutes: endTime.get('minutes'), seconds: startTime.get('seconds') });

@hijazikaram
Copy link
Author

dayjs doesnt let you set an object

@iamkun
Copy link
Owner

iamkun commented Apr 18, 2019

What's the best name for these two plugins?

AdvancedGet SetObject AdvancedAddSubtract?

@hijazikaram
Copy link
Author

AdvancedGet AdvancedSet

@hijazikaram
Copy link
Author

etc...

@iamkun
Copy link
Owner

iamkun commented Apr 18, 2019

But add && subtract is actually the same function, so there's no need adding two separate AdvancedAdd & AdvancedSubtract, but if there's only one AdvancedAdd, it may get some user confusing that why no AdvancedSubtract.

@hijazikaram
Copy link
Author

You can do AdvancedAddSubtract

@hijazikaram
Copy link
Author

Can you hit me up when you add them please so i can close this issue
Thanks!

@iamkun
Copy link
Owner

iamkun commented Apr 18, 2019

Sure. You could do dayjs.add().add().add() at this moment.

@hijazikaram
Copy link
Author

wow i didnt know that you can do that lol

@hijazikaram
Copy link
Author

can i do the same with .set

@hijazikaram
Copy link
Author

I did something like this for the .add
const minutes = +(minTime.slice(0, 2) * 60) + +minTime.slice(3, 5); newMinTimestamp = minTimestamp.add(minutes, 'minute'); minTimestamp = newMinTimestamp;

@hijazikaram
Copy link
Author

@iamkun is it possible i can do this endTime = day(df.endTime, 'HH:mm:ss'); instead of endTime = moment(df.endTime, 'HH:mm:ss'). Doing it right now will return NAN

@iamkun
Copy link
Owner

iamkun commented Apr 18, 2019

yes, customParseFormat plugin, please.

@hijazikaram
Copy link
Author

i have it added but its not doing anything

@hijazikaram
Copy link
Author

do i have to do something like day.customParseFormat()

@iamkun
Copy link
Owner

iamkun commented Apr 18, 2019

online demo or sample code, please.

@hijazikaram
Copy link
Author

hijazikaram commented Apr 18, 2019

import * as moment from 'moment'; import * as day from 'dayjs'; import * as utc from 'dayjs/plugin/utc'; import * as customParseFormat from 'dayjs/plugin/customParseFormat'; day.extend(customParseFormat); day.extend(utc); public updatetime() { const df = this.dateFilter; let startDateTime = moment(df.startDate); let endDateTime = day(df.endDate); let startTime = day() .utc() .startOf('day'); let endTime = day() .utc() .endOf('day'); console.log(endTime) if (df.startTime) { startTime = day(df.startTime, 'HH:mm:ss'); } if (df.endTime) { console.log(df.endTime) console.log(day(df.endTime).format('HH:mm:ss')) endTime = day(df.endTime, 'HH:mm:ss'); } startDateTime = startDateTime.set({ hour: startTime.get('hour'), minutes: startTime.get('minute'), seconds: startTime.get('second') }); // endDateTime = endDateTime.set({ // hour: endTime.get('hours'), // minutes: endTime.get('minutes'), // seconds: startTime.get('seconds') // }); df.startDate = startDateTime.toDate(); df.endDate = endDateTime.toDate(); }

@hijazikaram
Copy link
Author

@iamkun hope this helps

@hijazikaram
Copy link
Author

drf.endtime should always equal something like 12:04

@hijazikaram
Copy link
Author

I think i got it, im sending in a a time that doesnt have seconds, its breaking it. In moment, if the time doesnt have seconds, it automatically add the seconds to the time :00

@iamkun
Copy link
Owner

iamkun commented May 26, 2020

We just released the ObjectSupport plugin to support this. https://day.js.org/docs/en/plugin/object-support

@iamkun iamkun closed this as completed May 26, 2020
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

2 participants