import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';
dayjs('2020-99-78', 'YYYY-MM-DD').isValid()
dayjs@1.8.25
import dayjs from 'dayjs';
import dayjsBusinessDays from 'dayjs-business-days';
export class Class {
constructor() {
dayjs.extend(dayjsBusinessDays);
}
add(fechaInicio: Date, dias: number): Date {
return dayjs(fechaInicio)
.businessDaysAdd(dias)
.toDate();
}
}
import { Dayjs } from 'dayjs';
declare module 'dayjs' {
interface Dayjs {
businessDaysAdd(days: number);
}
}
error TS2339: Property 'businessDaysAdd' does not exist on type 'Dayjs'
Hiya!
I'm making a node.js library, and I want it to return a DayJS class, how do I set it up so it returns the DayJS Class (that people can use its methods on), and have it shown in my JSDOCS?
Do I use
const dayjs = require('dayjs')
or
const { Dayjs } = require('dayjs')
Thanks,
Sasial.
@iamkun I've gone and updated my code now,
Library:
/**
* TEST
*
* @returns {dayjs}
* @memberof APIClient
*/
async test() {
return dayjs()
}
Test Script
mylib.test().then(day => {
console.log(day.to(day.add(6, "m")))
})
Now while this works (returning a dayjs object), there's no VSC autocomplete or anything?
How can I set it up so it knows it's returning a dayjs object?
const dayjs = require('dayjs')
// Load DAYJS Plugins
var relativeTime = require('dayjs/plugin/relativeTime')
var utc = require('dayjs/plugin/utc')
var timezone = require('dayjs/plugin/timezone') // dependent on utc plugin
dayjs.extend(relativeTime)
dayjs.extend(utc)
dayjs.extend(timezone)
let a = dayjs("2000-01-01 01:02:03+07:00")
let b = a.add(1, 'day');
// what do I do here?
b.format("YYYY-MM-DD HH:mm:ssZ") === "2000-01-02 01:02:03+07:00"
I am having some timezone issues....I have some date/time objects that I have to convert from UTC time to EST. I need to compare the current time to a string that I convert into a date object. I can't seem to find a way to compare the 2 date/times where the comparison returns correctly. When the string that I have converted into a date object is before the current time, it is returning false (not before the current time). I don't understand why this is happening, unless it is because there is no timezone attached to the converted string date. When I try to attach a timezone to it, it doesn't seem to work - or it is attaching the GMT timezone instead of EST timezone. I am not sure what I am doing wrong.
let deploymentTime = dayjs.tz(`${parseInt(month)+1}/${date}/${year} ${deployHour}:${dataObj.minute.value} ${period}`, "America/New_York").format('M/D/YYYY h:mm a');
let otherTime = dayjs(`${parseInt(month)+1}/${date}/${year} ${deployHour}:${dataObj.minute.value} ${period}`).format('M/D/YYYY h:mm a');
console.log(dayjs().tz("America/New_York").toString())
console.log("DEPLOYMENT time: " +deploymentTime.toString());
console.log("other time: " +deploymentTime.toString());
console.log(dayjs().tz("America/New_York").isBefore(deploymentTime, 'minute'))
console.log(dayjs().tz("America/New_York").isBefore(otherTime, 'minute'))
logs out:
[0-0] Tue, 08 Dec 2020 16:58:53 GMT
DEPLOYMENT time: 12/8/2020 4:00 pm
other time: 12/8/2020 4:00 pm
[0-0] true
[0-0] false
@iamkun I am still striggling to get time in my local timezone. The system I am running in is running in UTC, but I need to convert the time to my local time of EST. I have tried setting the default tiemzone to EST, but when I call dayjs().tz() or dayjs().tz().local() it gives me the same time as just calling dayjs(). How do I convert time from UTC to EST?
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
dayjs.tz.setDefault("America/New_York")
console.log("date: " +dayjs().toString())
console.log("date with timezone: " +dayjs().tz().toString())
console.log("date with local timezone: " + dayjs().tz().local().toString())
logs out:
date: Tue, 19 Jan 2021 16:53:10 GMT
[0-0] date with timezone: Tue, 19 Jan 2021 16:53:10 GMT
[0-0] date with local timezone: Tue, 19 Jan 2021 16:53:10 GMT