dayjs#Dayjs TypeScript Examples
The following examples show how to use
dayjs#Dayjs.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: util.tsx From tams-club-cal with MIT License | 7 votes |
/**
* Returns the dayjs object, corrected to central timezone
*
* @param millis UTC millisecond time
* @returns The dayjs object in the correct timezone
*/
export function toTz(millis: number): Dayjs {
return dayjs(Number(millis)).tz('America/Chicago');
}
Example #2
Source File: util.ts From alauda-ui with MIT License | 7 votes |
export function formatDate(type: DateNavRange, dateValue: Dayjs, date: Dayjs) {
if (!dateValue) {
return null;
}
const label =
type === DateNavRange.Decade
? dateValue.year()
: type === DateNavRange.Year
? dateValue.month() + 1
: dateValue.date();
const cell = new DateCell(dateValue, label);
if (type === DateNavRange.Month && date.month() !== dateValue.month()) {
cell.isBackground = true;
}
return cell;
}
Example #3
Source File: utils.ts From hexon with GNU General Public License v3.0 | 7 votes |
export function getTimeData(date: Dayjs): IDateData[] {
const hour = date.hour()
const base = date.subtract(hour < 12 ? hour : hour - 12, "hour")
return new Array(12).fill(0).map(
(v, idx): IDateData => ({
text: `0${idx}`.slice(-2),
current: idx === hour % 12,
selected: idx === hour % 12,
date: base.add(idx, "hour"),
})
)
}
Example #4
Source File: UserNotes.ts From context-mod with MIT License | 6 votes |
//time: Dayjs;
// text?: string;
// moderator: RedditUser;
// noteTypeIndex: number;
// noteType: string | null;
// link: string;
constructor(public time: Dayjs, public text: string, public modIndex: number, public noteType: string | number, public link: (string | null) = null, public moderator?: RedditUser) {
}
Example #5
Source File: CalendarHeader.tsx From jmix-frontend with Apache License 2.0 | 6 votes |
/**
* It is taking from antd library.
* The default header contains a month selector which is not needed for us.
* TODO CalendarHeader could be removed after antd calendar will correct support `mode="month"`.
*/
export function CalendarHeader(props: CalendarHeaderProps) {
const {onChange} = props;
const divRef = React.useRef<HTMLDivElement>(null);
const prefixCls = 'ant-picker-calendar';
const fullscreen = true;
const sharedProps = {
...props,
prefixCls,
generateConfig: dayjsGenerateConfig,
onChange,
fullscreen,
divRef,
};
const [locale] = useLocaleReceiver("Calendar") as any
return (
<div className={`${prefixCls}-header`} ref={divRef}>
<YearSelect<Dayjs> {...sharedProps} locale = {locale.lang} />
<MonthSelect<Dayjs> {...sharedProps} locale = {locale.lang} />
</div>
);
}
Example #6
Source File: AgeDisplay.tsx From devex with GNU General Public License v3.0 | 6 votes |
AgeDisplay: React.FC<IProps> = ({ timestamp, className }) => {
const parsedTime: Dayjs = dayjs(timestamp / 1000);
return (
<OverlayTrigger
placement="top"
overlay={
<Tooltip id={"overlay-to"}>
{parsedTime.format("YYYY-DD-MM HH:mm")}
</Tooltip>
}
>
<div className={className}>
<span>{parsedTime.fromNow()}</span>
</div>
</OverlayTrigger>
);
}
Example #7
Source File: component.ts From alauda-ui with MIT License | 6 votes |
getDisabledTimeFn(
selectedDate: Dayjs,
type: keyof ReturnType<DisabledTimeFn>,
) {
if (selectedDate !== this._cacheSelectedDate) {
this._cacheDisabledTimeFn = this.disabledTime(selectedDate);
this._cacheSelectedDate = selectedDate;
}
return this._cacheDisabledTimeFn?.[type];
}
Example #8
Source File: helpers.ts From webapp with MIT License | 6 votes |
durationTimer = (
duration: Duration,
start: Dayjs = dayjs(),
format: string = "DD[d:]HH[h:]mm[m]"
): string => {
const end = start.add(duration);
const result = dayjs.duration(end.diff(start));
return result.format(format);
}
Example #9
Source File: dxc-date-input.component.ts From halstack-angular with Apache License 2.0 | 6 votes |
onSelectedChangeHandler(value: Dayjs) {
let _stringValue = this.getDateStringValue(value, this.format);
let _dateReturn = {
value: _stringValue,
date: value.isValid() ? value.toDate() : undefined,
error: this.dxcInputRef.error,
};
this.onChange.emit(_dateReturn);
if (!this.controlled) {
this.dateValue = value;
this.renderedValue = _stringValue;
}
this.onBlur.emit(_dateReturn);
this.closeCalendar();
}
Example #10
Source File: utils.ts From hexon with GNU General Public License v3.0 | 6 votes |
export function lastMondayInCurrentMonth(date: Dayjs, monday: Dayjs): boolean {
return monday.month() === date.month()
}
Example #11
Source File: DateRangePicker.tsx From condo with MIT License | 6 votes |
DateRangePicker: React.FC<RangePickerSharedProps<Dayjs>> = (props) => {
return (
<DatePicker.RangePicker
css={RANGE_PICKER_CSS}
allowClear={false}
suffixIcon={<DownOutlined />}
disabledDate={(date) => date > dayjs()}
format='DD.MM.YYYY'
separator={<MinusOutlined />}
{...props}
/>
)
}
Example #12
Source File: ScreenAnnounceView.tsx From takeout-app with MIT License | 6 votes |
AnnounceTimeItem: React.FC<{ tz: string; t: Dayjs }> = ({ tz, t }) => {
return (
<VStack spacing="0.6vw">
<Text fontWeight="500" fontSize="1.6vw" lineHeight="1.8vw">
{tz}
</Text>
<Text fontWeight="700" fontSize="3.2vw" lineHeight="3.8vw">
{t.format("HH:mm")}
</Text>
</VStack>
);
}
Example #13
Source File: index.tsx From ui with MIT License | 6 votes |
private getSingleSelectdState = (value: Dayjs): Partial<AtCalendarState> => {
const { generateDate } = this.state;
const stateValue: Partial<AtCalendarState> = {
selectedDate: this.getSelectedDate(value.valueOf()),
};
const dayjsGenerateDate: Dayjs = value.startOf('month');
const generateDateValue: number = dayjsGenerateDate.valueOf();
if (generateDateValue !== generateDate) {
this.triggerChangeDate(dayjsGenerateDate);
stateValue.generateDate = generateDateValue;
}
return stateValue;
};
Example #14
Source File: timeUtils.ts From vscode-todo-md with MIT License | 6 votes |
/**
* Get date or datetime ISO 8601
*
* Example: `2020-04-21` or `2020-04-30T09:11:17`
*
* Uses local time.
*
* @param includeTime Default is **false**
*/
export function getDateInISOFormat(date: Date | Dayjs = new Date(), includeTime = false): string {
const format = includeTime ? DATE_TIME_FORMAT : DATE_FORMAT;
return dayjs(date).format(format);
}
Example #15
Source File: App.ts From context-mod with MIT License | 5 votes |
startedAt: Dayjs = dayjs();
Example #16
Source File: Calendar.tsx From jmix-frontend with Apache License 2.0 | 5 votes |
CalendarDayjsAntd = generateCalendar<Dayjs>(dayjsGenerateConfig)
Example #17
Source File: PropertyValue.tsx From posthog-foss with MIT License | 5 votes |
DatePicker = generatePicker<Dayjs>(dayjsGenerateConfig)
Example #18
Source File: Bot.ts From tf2autobot with MIT License | 5 votes |
private loginAttempts: Dayjs[] = [];
Example #19
Source File: component.ts From alauda-ui with MIT License | 5 votes |
override writeValue(obj: Dayjs) {
super.writeValue(obj);
this.selectedDate = obj;
this.selectedTime = getTimePickerModel(obj);
this.anchor = obj || dayjs();
this.cdr.markForCheck();
}