momentjs

Set moment timezone in Jest tests

爷,独闯天下 提交于 2021-01-26 11:10:09
问题 I have the util function that is parsing given date (i.e. '2019-01-28') in specific date format and then using momentJS retrieving beginning of that day and converting it to ISO date format: dates.js import moment from 'moment' export const getApiDateFormat = (date, dateFormat = getLocaleDateString()) => moment(date, dateFormat) .startOf('day') .toISOString() I would like to test this function using Jest and set the specific timezone for moment to use those tests independent of my location.

Set moment timezone in Jest tests

社会主义新天地 提交于 2021-01-26 11:07:45
问题 I have the util function that is parsing given date (i.e. '2019-01-28') in specific date format and then using momentJS retrieving beginning of that day and converting it to ISO date format: dates.js import moment from 'moment' export const getApiDateFormat = (date, dateFormat = getLocaleDateString()) => moment(date, dateFormat) .startOf('day') .toISOString() I would like to test this function using Jest and set the specific timezone for moment to use those tests independent of my location.

Set moment timezone in Jest tests

为君一笑 提交于 2021-01-26 11:04:29
问题 I have the util function that is parsing given date (i.e. '2019-01-28') in specific date format and then using momentJS retrieving beginning of that day and converting it to ISO date format: dates.js import moment from 'moment' export const getApiDateFormat = (date, dateFormat = getLocaleDateString()) => moment(date, dateFormat) .startOf('day') .toISOString() I would like to test this function using Jest and set the specific timezone for moment to use those tests independent of my location.

How to convert from GMT/UTC to local time and back using momentjs?

寵の児 提交于 2021-01-20 12:21:26
问题 I have the following string: "December 25, 2018 01:02:20" I intend this to be GMT/UTC Using moment.js, how do I convert this to local time and back to UTC? When I do: moment(myDateString).local() Then later to try to convert back: moment(myDateStrig).utc() They both yield different results. How do I make it so that I can convert the time I have from UTC to local, then back to UTC? Note: When I try the .utc() function on the string "December 25, 2018 01:02:20" I get a different time. When I do

Format column header dates in FullCalendar

时光怂恿深爱的人放手 提交于 2021-01-20 07:09:58
问题 I've been trying to change the format of the dates that appear in the day column headers on the Fullcalendar week/timegrid view: I'm using V5 in conjuction with moment.js. Searching through the docs, I ended up here: https://fullcalendar.io/docs/v5/day-header-render-hooks This is the code I've tried when initialising the calendar: dayHeaderFormat: function(date){ return moment(date.weekday).format('ddd'); } This results in showing today (Thu) for every header, rather than the correct days. My

Format column header dates in FullCalendar

淺唱寂寞╮ 提交于 2021-01-20 07:07:34
问题 I've been trying to change the format of the dates that appear in the day column headers on the Fullcalendar week/timegrid view: I'm using V5 in conjuction with moment.js. Searching through the docs, I ended up here: https://fullcalendar.io/docs/v5/day-header-render-hooks This is the code I've tried when initialising the calendar: dayHeaderFormat: function(date){ return moment(date.weekday).format('ddd'); } This results in showing today (Thu) for every header, rather than the correct days. My

change the first day of the week with work week view

久未见 提交于 2021-01-05 11:31:33
问题 I'm trying to change the first day of the work_week view with react big calendar but I didn't found a way to do it... I was able to change the first day of the week view but nothing helped with work week... any ideas? This is how I changed the first day of the week view: import "moment/locale/en-gb"; moment.locale("en-gb", { week: { dow: 0, }, }); const localizer = momentLocalizer(moment); 回答1: Unfortunately, the only way to do this is by defining a custom 'View', rather than using the 'work

Customize numeric values in Moment Arabic localization

一曲冷凌霜 提交于 2021-01-02 08:21:21
问题 I want to create my own locale in moment.js, its parent should be the Arabic local but I want only to change to numeric format to display 0-9 , not the default display. As per documentation, I can start with that: moment.defineLocale('ar-sa-mine', { parentLocale: 'ar-sa', /* here I need to specify the numeric: change **this ٢٩ to 29** */ }); 回答1: If you look at locale/ar-sa.js code you will note that moment uses preparse and postformat to convert from numeric characters to arabic. You can

Function to convert PHP date format to Javascript date format (not the date itself !)

久未见 提交于 2020-12-21 03:55:53
问题 I am looking for easy way to convert PHP date format (i.e. Y-m-d H:i:s) to javascript date format (respectively YYYY-mm-dd HH:mm:ss). I don't want to convert the date (there are already answers for this question), I am looking for tool/function to convert the format code (which I don't know yet, as it is defined by the user in application). User can define it in different ways defined by PHP date() i.e. 'Y/m/d H:i' or 'Y-d-m H-i' and I need to use the same format when displaying date in

Function to convert PHP date format to Javascript date format (not the date itself !)

佐手、 提交于 2020-12-21 03:54:16
问题 I am looking for easy way to convert PHP date format (i.e. Y-m-d H:i:s) to javascript date format (respectively YYYY-mm-dd HH:mm:ss). I don't want to convert the date (there are already answers for this question), I am looking for tool/function to convert the format code (which I don't know yet, as it is defined by the user in application). User can define it in different ways defined by PHP date() i.e. 'Y/m/d H:i' or 'Y-d-m H-i' and I need to use the same format when displaying date in