Lets assume we have the following date: 2019, 11, 1.
I want to display only the month's name, but MMMM formatting results into "ноября", when I expect to get "ноябрь".
It works OK in moment.js (locale: ru):
// if format starts with month name
moment([2019, 11, 1]).format('MMMM') => 'ноябрь'
// if format doesn't start with month name
moment([2019, 11, 1]).format('DD MMMM') => '1 ноября'
I would like to switch to moment.js, although I am already utilizing the library which strictly depends on date-fns. How can I achieve the format to show the month's name correctly in Russian language?
date-fns's GitHub repo
My workaround for this problem in use case for react-datepicker was to pass month name in cyrilic as format.
const getMonthName = (date) => {
const months = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
return months[date.getMonth()];
};
<DatePicker dateFormatCalendar={ getMonthName(new Date()) } />
format(new Date(2014, 1, 11), getMonthName(new Date(2014, 1, 11)))
Worked under my limited use case
You need to change MMMM to LLLL
Related
we have an element on our booking page ".ItineraryDate [datetime]:last" which displays the date of the last flight in the itinerary (e.g. Tue 7 Jul). For the purpose of a Cypress test, I need to extract the day (e.g. 7) and the month (e.g. Jul).
cy.get(".ItineraryDate [datetime]:last").then($span => {
const lastLegDate = $span.text()
})
This code creates const Tue 7 Jul, but I need to use only the day and the month. Do you know how could I extract it?
Cypress automatically includes moment.js and exposes it as Cypress.moment.
Refer moment formats
You can extract the month and day in anyway you want using Cypress.moment.
Markup:
<div class="date">Tue 7 Jul</div>
Test:
cy.get('.date').then(($el) => {
cy.log('original: ' + $el.text());
const dateString = Cypress.moment($el.text(), 'ddd D MMM')
const month = Cypress.moment(dateString, 'ddd D MMM').format('MMMM');
const day = Cypress.moment(dateString, 'ddd D MMM').format('D');
cy.log(`After formatting month = ${month}`);
cy.log(`After formatting day = ${day}`);
expect(month).to.equal('July');
expect(day).to.equal('7');
});
Screenshot:
Playing in groovyConsole with DateTimeFormatter and DateTimeFormatterBuilder
String inputDateString = "31.2.58" // german date format
dtfIn = DateTimeFormatter
.ofPattern ( "d.M.uu" )
.withResolverStyle ( ResolverStyle.STRICT )
dtfIn.parse(inputDateString) // ERROR as expected
...but
// with base range 1937-2034
dtfIn = new DateTimeFormatterBuilder()
.appendPattern("d.M.")
.appendValueReduced(ChronoField.YEAR, 2, 2, Year.now().getValue() - 80)
.parseStrict()
.toFormatter()
dtfIn.parse(inputDateString) // Result: 1958-02-28
So DateTimeFormatterBuilder with .parseStrict() would parse rather SMART, which DateTimeFormatterBuilder shouldn't do at all but either STRICT or LENIENT (?)'
With day numbers over 31 I'll get an error.
The problem seem to be .appendValueReduced(). Without it I'd become an error as expected.
What do I do wrong?
Thanks
Rawi
DateTimeFormatter from DateTimeFormatterBuilder.toFormatter() is indeed SMART as documented:
The resolver style will be SMART
To obtain STRICT one has to use DateFormatter.withResolverStyle(ResolverStyle)
in this case as follows:
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
I am trying to set the date in a date picker field in a Windows environment (shown in attached images). It's not an AutoIt date control (I did not create this field). I used the following code:
; enter from date
$sFromDate = "09/01/2017"
ControlFocus($hWnd, "", "WindowsForms10.SysDateTimePick32.app.01")
ControlSetText($hWnd, "", "WindowsForms10.SysDateTimePick32.app.01", $sFromDate )
The AutoIt Window Information Tool shows info about the control but not the items (month/day/year) inside it. I am looking for any tool to set the date, not necessarily AutoIt.
See description and example of _GUICtrlDTP_SetSystemTime
https://www.autoitscript.com/autoit3/docs/libfunctions/_GUICtrlDTP_SetSystemTime.htm
Try to use this example:
#include <GuiDateTimePicker.au3>
Local $a_Date[7] = [False, #YEAR, 8, 19, 21, 57, 34]
$hDTP = ControlGetHandle("Set_Window_Title_Here", "", "WindowsForms10.SysDateTimePick32.app.01")
_GUICtrlDTP_SetSystemTime($hDTP, $a_Date)
I have got below code, where I am sending the formatted date and time to my XSLT and which is giving a XML as output.
#importXSLT "tcm:228-190529-2048" As expandXSLT
#importXSLT "tcm:228-642694-2048" As renderXSLT
Dim xml, currentDateTime, datLong , datLongTime , fullDate
Set xml = getNewDomDocument()
xml.loadXML TDSE.GetListPublications(3)
expandXSLT.input = xml
Call expandXSLT.addParameter("publication", Component.Publication.Id)
expandXSLT.transform
xml.loadXML(expandXSLT.output)
'WriteOut xml.xml
currentDateTime = now()
datLong = FormatDateTime(currentDateTime, 1)
datLongTime = FormatDateTime(currentDateTime, 3)
fullDate = datLong &" "& datLongTime
renderXSLT.input = xml
Call renderXSLT.addParameter("currentPublishedDate", CStr(fullDate))
renderXSLT.transform
WriteOut renderXSLT.output
Set xml = Nothing
Now above logic for doing date formatting is same for two outputted XML, but suprising I am getting different output for both the files.
First File gives - Sunday, October 23, 2011 8:52:36 AM as output
Second File gives - 23 October 2011 09:14:45 as output.
Please suggest what can be reason as well as solution also, and one more thing if I want output as below for both the file as 23 October 2011 09:14:45 AM
Thanks!!
Before you do the date formatting, try to explicitly set the locale using something like SetLocale(2057).
2057 is UK format which seems to be what you want, otherwise look at this Locale ID Chart to find the correct value.
I am working on an application in which I need to get the current year, month, and day. Is there a way to get this information in the pre block of a rule?
Can I get this data as a string or a number or both?
There are currently time functions documented on http://docs.kynetx.com/docs/Time but none of them seem to work for what I am trying to do.
Is there a way to set the timezone when getting this data?
I was able to do it using strftime which appears to be an undocumented feature so use with caution.
ruleset a60x518 {
meta {
name "date-test"
description <<
date-test
>>
author "Mike Grace"
logging on
}
rule testing {
select when pageview ".*"
pre {
retTime = time:strftime(time:now({"tz":"America/Denver"}), "%c");
month = time:strftime(time:now({"tz":"America/Denver"}), "%B");
year = time:strftime(time:now({"tz":"America/Denver"}), "%Y");
day = time:strftime(time:now({"tz":"America/Denver"}), "%d");
}
{
notify("time",retTime) with sticky = true;
notify("month",month) with sticky = true;
notify("year",year) with sticky = true;
notify("day",day) with sticky = true;
}
}
}
App run on example.com twice. Once with the timezone set to New York and onother time set to Denver
I used this site http://www.statoids.com/tus.html to get the correct strings to use for the timezone. I have no idea if they all work. I just found this site and tried a few and they worked so use with caution.
Perhaps the docs got reverted. For convenience, here is the documentation for strftime:
time:strftime()
Convert a datetime string to a different format
Usage
time:strftime(`<string>`,`<format>`)
Valid format arguments to strftime follow the POSIX strftime conventions.
Samples
time:strftime(xTime,”%F %T”) # 2010-10-06 18:15:24
time:strftime(xTime,”%F”) # 2010-10-06
time:strftime(xTime,”%T”) # 18:19:29
time:strftime(xTime,”%A %d %b %Y”) # Wednesday 06 Oct 2010
time:strftime(xTime,”%c”) # Oct 6, 2010 6:25:55 PM
The other time functions:
time:now()
Current datetime based upon user’s location data
Usage
time:now()
time:now({“tz” : <timezone>)
time:new()
Create a new RFC 3339 datetime string from a string (allows some flexibility in how the source string is formatted)
Usage
time:new() # Equivalent to time:now()
time:new(<string>)
Valid formats for the datetime source string can be found in ISO8601 (v2000).
time:add()
Add (or subtract) a specific number of time units to a source string
Usage
time:add(<string>,{<unit> : n})