-1

How can i migrate this line into luxon from moment, the code sample is given below,

This code sample is in moment, and i want to do it in luxon.

  timezone: null,
   getIn: moment().hour(14).minute(0)
      .second(0)
      .millisecond(0),

   getOut: moment().add(2, 'days').hour(11).minute(0)
      .second(0)
      .millisecond(0),


   getIn: 
  moment(luxon.DateTime.fromISO(moment(getIn).toISOString(), { zone: home.timezone }).toJSDate()),

getOut: 
  moment(luxon.DateTime.fromISO(moment(getOut).toISOString(), { zone: home.timezone }).toJSDate()),

James Z
  • 12,209
  • 10
  • 24
  • 44
GCT
  • 43
  • 7
  • Which is your desired output? Do you need to calculate "today at 14:00" and "in 2 days at 11:00" using luxon? You can refer to [For Moment users](https://moment.github.io/luxon/#/moment) section of the docs to get information on how luxon works compared to momentjs – VincenzoC Oct 17 '22 at 10:52

1 Answers1

1

The equivalent for those would be:

Proven to produce the same results with this Playground (look at console output in the right panel)

///moment
getIn: moment().hour(14).minute(0)
      .second(0)
      .millisecond(0),

//luxon
getIn: DateTime.now().startOf('day').set({ hour: 14 })
//moment
getOut: moment().add(2, 'days').hour(11).minute(0)
      .second(0)
      .millisecond(0)

//luxon
getOut: DateTime.now().startOf('day').plus({ days: 2 }).set({ hour: 11 })
Svetoslav Petkov
  • 1,117
  • 5
  • 13
  • Thank you very much i checked in the console yes its working @SvetoslavPetkov – GCT Oct 17 '22 at 10:56
  • But do i need to add like this, DateTime.now().startOf('day').plus({ days: 2 }).set({ hour: 11, minute: 0, second: 0, millisecond: 0 }); @SvetoslavPetkov – GCT Oct 17 '22 at 10:59
  • I am also having problem to migrate this getIn: moment(luxon.DateTime.fromISO(moment(getIn).toISOString(), { zone: home.timezone }).toJSDate()), into luxon @SvetoslavPetkov – GCT Oct 17 '22 at 11:00
  • 1
    1. You do not need to set minutes, seconds ana milliseconds to 0. `startOf('day')` already sets everything to 0. 2. What is the desired output of this getIn, getOut. I see you mix moment and luxon within same lines. You want to parse the result of the getIn and output it into different timezone ? – Svetoslav Petkov Oct 17 '22 at 11:16
  • no actually i want to make this line by using full luxon i will remove the moment but what is the exact way i am confused? will this work like this, luxon.DateTime.fromISO((getIn).toISO(), { zone: home.timezone }.toJSDate()), luxon.DateTime.fromISO((getOut).toISO(), { zone: home.timezone }.toJSDate()), is this line correct @SvetoslavPetkov – GCT Oct 17 '22 at 12:20
  • Yes you are right @SvetoslavPetkov – GCT Oct 17 '22 at 12:34
  • 1
    I still do not get what the output would be in order to help you. Luxon has a set time zone, method `.setZone()`. – Svetoslav Petkov Oct 18 '22 at 05:38
  • Hello @SvetoslavPetkov Can you help me in this issue, https://stackoverflow.com/questions/74098865/issue-with-converting-momentjs-into-luxonjs-typescript as I am replacing from moment into luxon, this sample code in my project. – GCT Oct 18 '22 at 08:09