How to check if a 'any'-Object fits a union type?

I’m getting an object (type: any) of an external library A and want to pass it to a function from a library B. That function expects a Type B-Input, which is a Union Type (number | string | somethingCustom). How can I check if the object is compatible? (More precise: momentJS expects a MomentInput. An… Read More How to check if a 'any'-Object fits a union type?

using moment js utc offset to filter an array of objects

i have an array of timezones that looks as follows {name: ‘(UTC) Coordinated Universal Time’, offset: ’00:00:00′, id: ‘UTC’} {name: ‘(UTC+00:00) Dublin, Edinburgh, Lisbon, London’, offset: ’00:00:00′, id: ‘GMT Standard Time’} {name: ‘(UTC+03:00) Istanbul’, offset: ’03:00:00′, id: ‘Turkey Standard Time’} {name: ‘(UTC+04:00) Astrakhan, Ulyanovsk’, offset: ’04:00:00′, id: ‘Astrakhan Standard Time’} so i am trying to… Read More using moment js utc offset to filter an array of objects

Discord.js specific timestep for code block

How can I make such a time format? Sample code I made. .setDescription(`📆 Your account was opened on ${moment(member.user.createdAt).startOf(‘day’).fromNow()}.`) I want to learn how to show the date of account establishment and server joining as in the image. >Solution : Discord will convert any text in the format of <t:SECONDS> into a timestamp. Just replace… Read More Discord.js specific timestep for code block

mongoDB Not Returning Query When Trying to Filter By Date

I am trying to find all documents that are created greater than or equal to a month ago. But when I query the DB it returns nothing when doing the following code: console.log(moment().add(-31, "days").toDate()) // this logs 2022-09-30T07:27:26.373Z let filter = { companyId: companyId, userId: userId, _created_at: {$gte: moment().add(-31, "days").toDate()} }; db.collection("Users") .find(filter) .count() .then(count… Read More mongoDB Not Returning Query When Trying to Filter By Date

Understanding particular date/time format

What is the use of the following format, supported by Moment.js? > const moment=require(‘moment’) undefined > moment().format(‘h AM/PM’) ‘3 PM10/P10′ Particularly, what does PM10/P10 mean? From the docs here. >Solution : It’s parsing the string through its constituent pieces of the date time spec: https://en.wikipedia.org/wiki/ISO_8601 However the wiki it’s tricky to understand, so to breakdown… Read More Understanding particular date/time format

Get nearest time from array javascript

I have an object like this var object = { "Fajr": "04:29 (WIB)", "Sunrise": "05:39 (WIB)", "Dhuhr": "11:43 (WIB)", "Asr": "14:48 (WIB)", "Sunset": "17:48 (WIB)", "Maghrib": "17:48 (WIB)", "Isha": "18:53 (WIB)", "Imsak": "04:19 (WIB)", "Midnight": "23:43 (WIB)", "Firstthird": "21:45 (WIB)", "Lastthird": "01:42 (WIB)" } and i want to use moment diff https://momentjs.com/docs/#/displaying/difference/ . But after… Read More Get nearest time from array javascript

How to get date string from day number and month number using moment?

dayNumber: 28, monthNumber: 2, expected output using moment "2022-02-28" What I’ve tried const date = moment() .month(monthNumber) .days(dayNumber) .format("YYYY-MM-DD"); but that gives me something like "2022-03-17" what am I doing wrong? >Solution : You have two errors in your code: The first one is that you need to replace the days function call with date… Read More How to get date string from day number and month number using moment?

convert data time to a desired format in js

I am trying to convert 2022-09-13T08:06:12.328+0000 to 13 September at 1:36 PM using javascript. In order to make things easier, I thought to install moment js and tried the conversion as below. console.log(moment(‘2022-09-13T08:06:12.328+0000’).calendar()); But it will print the output as Yesterday at 1:36 PM. So is there any way to change the format as I… Read More convert data time to a desired format in js