Open tukusejssirs opened 4 years ago
We use ISO 639-2 country code. Check lists short codes for language here. https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
Okay, then if I’ll go the route of having three locales, how does the locale inheritance work? I don’t want to define common locale parts in all three locales.
Okay.
Okay, I’ll do my best.
Arabic numerals = 1, 2, 3, … Roman numerals = I, II, III, IV, …
Date example: XX Iunii MMXX = 20 June 2020
Time format would 24h in Arabic numerals, e.g. 13:24.
Now, my question is about the conversion from Arabic numerals to Roman numerals: is there a builtin converter or should I create a function within the locale? If I need to create a function and I create it in the main, la.js
locale, will it be inherited (i.e. defined) in the ‘sublocales’ like la-va.js
?
la
is code for Latin according to ISO 369-2. However, I believe that country code system you use is ISO 3166-1 alpha-2, which assigns VA for Vatican / the Holy See.2 the best way might just be simple copy-paste.
Yes, you have to create a function to make the conversion in locale file.
I have created the la.js
locale. I isn’t perfect, as currently the relativeTime
format uses Nominative case only (and thus ad %d anni
[in %d years] is grammatically incorrect, but %d anni
[%d years] is correct). Is there a way to check within the locale what is the context of the queried value? I think there is none, but without that I can’t see a way to return the correct form of the words. I wish there would be a way (like extra argument added to dayjs
when invoking, as this would be other languages too (and then I could fix moment/moment#5408 (read this comment to get the main issue).
Anyway, as there is no la.js
in Moment, should I create a test that would check if the output matches a fixed string?
I wanted to test the locale locally, but with my limited knowledge I could not make it work. This is what I have done:
npm install && npm run-script build
.testLa.js
with the following content:const dayjs = require('./dayjs.min.js');
dayjs.locale('la')
var l = dayjs.locale()
console.log(l)
node testLa.js
) and I have expected the output to be la
, but it was en
.Now, I have read the docs, but adding require('dayjs/locale/la')
throwed the following error:
$ node testLa.js
internal/modules/cjs/loader.js:960
throw err;
^
Error: Cannot find module 'dayjs/locale/la'
Require stack:
- /home/ts/git/c10n/dayjs/testLa.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/home/ts/git/c10n/dayjs/testLa.js:2:1)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/home/ts/git/c10n/dayjs/testLa.js' ]
}
I understand that the module was not found, but even if I change the path to src/locale/la
, it won’t find anything.
Anyway, I’ve just create a PR, but it definately needs to be reviewed.
Sorry, I was busy lately. Could you help me with running dayjs
from terminal using directly the code in the src/
folder? That way I could double-check if all tests pass more easily. Thanks for you help.
I would manually change 'dayjs/locale/la' to '../src/locale/la' 😢
I would manually change 'dayjs/locale/la' to '../src/locale/la' cry
Where would you do that?
I would manually change 'dayjs/locale/la' to '../src/locale/la' cry
Where would you do that?
to replace this Error: Cannot find module 'dayjs/locale/la'
I have tried out your suggestion, but it still does not work, see below. All my scripts are located in the repo root.
node testLa2.js
(with require
)node testLa2.mjs
(with require
)node testLa2.js
(with import
)node testLa2.mjs
(with import
)please use npm test
to test the source code
Indeed, you’re right, there are failing tests, but I did not change anything in those files.
All of our tests should be passed. You can submit a pull request with any change and test with our CI to see if there is an environmental issue.
I’ve no idea how to fix those errors, but somehow it uses GMT+1 timezone instead of UTC.
Note that I use CET (winter timezone; GMT+1) and CEST (summer timezone; GMT+2) locally; although it should not be connected, it might be.
I'll try CET to see if I can reproduce this later.
@iamkun, I have just cloned your repo (dev
branch, cf8b6a0) and run npm install && npm test
. The dependencies seemed to be installed successfully (some warnings about deprecated modules/versions were output though), but the tests fail (2 test suites / 10 tests). See the outputs below.
npm install
npm test
Oh, I see. Because of DST, some of the tests failed because of a fixed datetime string
Hi, @tukusejssirs
I have made a pr https://github.com/iamkun/dayjs/pull/1053 to fix this issue.
Can you please help me test it to see if it works?
@iamkun, I still have no idea why all the above-mentioned test scripts of mine fail to use la
and return the desired values.
I have run npm install && npm test && npm run build
to build to library (dayjs.min.js
), but it does not contain the Latin locale (why? what additional steps are required to get the Latin locale into the library?).
Also if I import or require ./src/locale/la.js
(or ./src/locale/la
) in the script, it always fails; either because of the import
statement in the la.js
file (while the script has .js
extension; error: SyntaxError: Cannot use import statement outside a module
) or there is an unexpected token '.'
(.
meaning the CWD).
I am fairly sure that this are a newbie mistake, but it seams I can’t find it. AFAIK, import
statements can be used in the modules or .mjs
scripts only, while require
in .js
scripts.
Thanks for your help.
you can check this as a reference test/locale/cs.test.js and create a test file to test Latin locale
I cannot do it the way it is in cs.test.js
, because in there, the values are compared with Moment output, while Moment does not include a Latin locale.
I need to do it the way it is in sv.test.js
.
Still, I’d like to have test script before I push it to the repo, therefore I wish I could run a script using the dayjs
module from src/
folder. For example, in romcal (in F-TypeScript
branch), I can run node -r ts-node/register -r tsconfig-paths/register romcalTest.ts
(while romcalTest.ts
is in the repo root folder and CWD is also the repo root folder) and use import romcal from './src';
to use the library without building it for testing purpose. Note that romcal is a TypeScript library.
Note that I could not make import dayjs from './src'
work in here, because:
.js
file, I get the following error: SyntaxError: Cannot use import statement outside a module
(which is understandable);.mjs
file, I get the following error: Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/home/ts/git/c10n/dayjs_ts/src' is not supported resolving ES modules, imported from /home/ts/git/c10n/dayjs_ts/ttt.mjs
(which I don’t understand and am not capable of solving it).Anyway, I don’t care how this would be solved, as long as I can use dayjs
library locally using the files in src/
. :smiley:
What I mean is that you could create a test file named la.test.js
, and write any test you want in it (including console.log).
Then just run npm test
Can you tell me why dayjs('2020-01-01').locale('la').format('LL')
outputs LL
string? Same for L
.
And D. MMMM YYYY
outputs 1. ianuarius 2020
instead of 1. ianuarii 2020
(there is a getMonthInGenitive()
function which changes the grammar case to genitive); does this mean I need to (re-) define the MMMM
in the la.js
file?
Update: I needed to add advancedFormat
, that is the following to lines into la.test.js
import localizedFormat from '../../src/plugin/localizedFormat'
dayjs.extend(localizedFormat)
But now I receive NamN
instead of ianuarii
(January in Latin in genitive). For example:
// la.js
LL: ['D ', getMonthInGenitive('MMMM'), ' ', romanise('YYYY')].join(''),
// la.test.js
console.log('testLL : ', dayjs('2020-01-01').locale('la').format('LL'))
// output in `npm test`
testLL : 1 NamN
// expected output in `npm test`
testLL : 1 ianuarii MM
Update 2: One of the problems lays in the argument of romanise()
function: I put there YYYY
as string; how can I send the year as number? Same would be the problem with the getMonthInGenitive()
function, which needs to get the name of the month in Latin in nominative case (one from months
key).
What I mean is that you could create a test file named
la.test.js
, and write any test you want in it (including console.log).Then just run
npm test
I understand what you mean, but I still want to be able to run a script using dayjs
library loaded from src/
folder, because the npm test
ways is absolutely slow for my needs. I want to test each and every definition in la.js
by hand before I put it into la.test.js
. Reason? I don’t trust myself in this, because I have little to no experience with NPM and creating tests as such. However, I can do it, but I need a way to run dayjs
from src/
.
npm test
does exactly what you want to test dayjs from src/
live.
It will be better if you could test it your self, cause I don't know much about the getMonthInGenitive
function and don't know what's the expected output.
npm test
does exactly what you want to test dayjs fromsrc/
live.
Okay, I see I can’t make you help me with this subissue. :smiley: I’ll run node node_modules/jest/bin/jest.js test/locale/la.test.js --coverage=false
then, in order to test my stuff.
It will be better if you could test it your self, cause I don't know much about the
getMonthInGenitive
function and don't know what's the expected output.
Well, actually I have tested it, but within a separate script (i.e. without using dayjs
).
That function is quite simple: it accepts one argument (a month name in Latin in nominative) and returns the genitive form of that month.
The whole problem is that I don’t know how to send it the name of the month in locale.formats.LL
. Currently, it returns a string (MMMM
), not the name of the month (e.g. ianuarius
). Can you help with this please?
PS—I don’t even understand, how the translate
funtcion from cs.js
gets its arguments. in locale.relativeTime
, no argument is supplied. Maybe if you make me understand this, I might be able to make it work.
If I understand you correctly, https://day.js.org/docs/en/customization/relative-time#additional-token-processing is what you are looking for about locale.relativeTime
in cs.js
.
If I understand you correctly, https://day.js.org/docs/en/customization/relative-time#additional-token-processing is what you are looking for about
locale.relativeTime
incs.js
.
That might work, however, does it work with locale.formats
too? The link from the docs you shared with me states it works with locale.relativeTime
; it does not talk about locale.formats
.
No at this moment.
locale.formats
will only do the replacement from 'MMMM' to the corresponding month name from localeObject.months
Then my functions in la.js
won’t at all.
Unless you know of another way. Here is what I need to do with MMMM
and YYYY
:
For months, I need to return month name in genitive case (i.e. substitute the form in nominative case with one in genitive case). For this I need to know what month is to be output, either as a number (1-12
or 0-11
) or month name (e.g. ianuarius for January).
For year: I need to convert the year in Arabic numerals (e.g. 2020
) to year in Roman numerals (e.g. MM
). For this purpose, we definitely need to process the year (as an int) using the romanise()
function.
PS:
1 January
→ 1 ianuarii
; it should not be changed for month name + year, e.g. ianuarius MM
).Something you can do is that month name also accepts a function with days instance and format passed in https://day.js.org/docs/en/customization/month-names#additional-token-processing
Something you can do is that month name also accepts a function with days instance and format passed in https://day.js.org/docs/en/customization/month-names#additional-token-processing
You mean I can replace locale.months
with the following code and it’ll work?
months: function (dayjsInstance, format) {
if (/^MMMM/.test(format)) {
return 'ianuarius_februarius_martius_aprilis_maius_iunius_iulius_augustus_september_october_november_december'.split('_');
} else {
return 'ianuarii_februarii_martii_aprilis_maii_iunii_iulii_augusti_septembris_octobris_novembris_decembris'.split('_');
}
},
Update: No, it does not. It returns all months in genitive (comman-separated), therefore it is a good step forward, but we ain’t there yet. :smiley:
Update 2: I think I need to know what are the monthShortFormat[dayjsInstance.month()]
and monthShortStandalone[dayjsInstance.month()]
functions. How should they look like?
Update 3: Nevermind, I’ve fixed it using the code from ru.js
(found it via #900) and hr.js
.
Last thing to fix is the conversion of the year from Arabic numerals to Roman numerals. I have a function (romanise()
) which accepts a year (as an int) and it works as expected. Can I somehow ‘plug it in’ somewhere?
IMHO, it might a better idea to implement it into dayjs
itself and use a kind of flag if one wants to output the year (or month or day of month) in Roman numerals.
For example:
2019. XII. 25.
).Update: Here’s link to romanise()
function.
Update 2: I tried the following code (based on monthStandalone
), but it does not work. I presume I can’t use the same logic for years.
const romaniseYear = (dayjsInstance, format) => {
return romanise(dayjsInstance.year())
}
I'd prefer it as a separate plugin.
Is that something you could create and place under plugins/
folder?
Oh, sorry I just misundertand what you mean.
IMO, just leave this romanise() function in the locale file. That would be enough right now.
IMO, just leave this romanise() function in the locale file. That would be enough right now.
I’ve no problem with that, however, how can I add the year (as an int) as argument to the function? romanise('YYYY')
, obviously, does not work.
Update: Just a reminder: I need to romanise the year in locale.formats
, as well as anywhere where the year is requested (i.e. Y+
, because AFAIK in Latin, the year is never abbreviated).
As far as I can tell, seems there is no way to convert year to anything other than the year number.
You may still have to consider making a plugin like buddhistEra
to get what you want.
You may still have to consider making a plugin like
buddhistEra
to get what you want.
Okay, I’ll do my best.
buddhistEra
adds additional date format (BB
and BBBB
). I am looking for replacing all years (be it YY
or YYYY
, therefore I think should use YY+
regex) with romanised year. This is a requirement, however, I am not sure, if I can simply replace the year in the dayjs
object, because that would change the data type (from int to string). What do you think?
@iamkun, in case I cannot replace the year in dayjs
object, I would choose:
RR
/RRRR
date format for romanised years (both would output the same thing, e.g. MM
for 2000
;TT
for romanised months (e.g. X
for October
/10
;OO
(uppercase letter O) for romanised days of months (e.g. XXIII
for 23
).If you disagree with these, let me know.
Anyway, I tried to modify the code in buddhistEra
(copied to src/plugin/romanisation
; let me know if you disagree with the name of the plugin). Below you can find my currect version of the code.
The thing is, it does not work for some reason. As you can see, I left there console.log('plugin : ', year)
, which outputs the correct romanised year, but the output of the plugin itself (i.e. replacement of RRRR
or RR
) is incorrect, e.g. for year 2020
it outputs 0115778332001577833200
. I am not sure what it means or how what that number created; I suspect it somehow converts the characters into their hex representation or what.
romanisation
@tukusejssirs Is there something we can check as a reference of the format token? like JAVA or something.
And actually, this plugin is becoming much more complex than we expected earlier, and we may release it in a separate repo like https://github.com/alibaba-aero/jalaliday so that you can get better control of the code logic, cause it's difficult for us to maintain these logic.
@tukusejssirs Is there something we can check as a reference of the format token? like JAVA or something.
No reference, because I couldn’t find any programming language with Roman numerals for year/dom/month implemented. Those date format (R
/T
/O
) are just my attempt to use something what is not used in dayjs
yet.
And actually, this plugin is becoming much more complex than we expected earlier, and we may release it in a separate repo like https://github.com/alibaba-aero/jalaliday so that you can get better control of the code logic, cause it's difficult for us to maintain these logic.
If you can guide me … Because I am not an experienced programmer (am I a programmer at all?). All I need is Latin locale for romcal, which use dayjs
, therefore I need to implement Latin locale into dayjs
. It is mostly done (apart from the tests, which still need some tending), but I need at least the romanised year, which would be ideally placed instead of each year (i.e. YY
and YYYY
). If that is not possible, I am open to use the same logic as the buddhistEra
plugin uses.
[…] cause it's difficult for us to maintain these logic.
May I know what is the difficult part of this logic? :smiley:
Day.js accepts all PRs related to adding locale. However, as for official plugins, we'd like to keep it in a fixed amount,maybe, just enough to add APIs the same as moment.js. That's why I advice you to to manage this plugin by your own.
Day.js accepts all PRs related to adding locale. However, as for official plugins, we'd like to keep it in a fixed amount,maybe, just enough to add APIs the same as moment.js. That's why I advice you to to manage this plugin by your own.
Okay, I got it. Just a quick question: therefore there is no way (or intention) to add a plugin for romanisation of the year to the list of the official plugins?
I don't think we have the ability right now.
@iamkun, how can I test ordinal numbers? Does it only work with Do
(i.e. days of months)? Why does it not work with years (YY
and YYYY
) and months (M
)?
Yes, ordinal only works for Do
at present.
As far as I can see, it's better to make a plugin yourself for the romanization ordinal to get the best result that you expected. Cause it has too much different than other locales that we supported.
Yes, ordinal only works for
Do
at present.
Thanks for clarification. :smiley:
Cause it has too much different than other locales that we supported.
Well, indeed you don’t support romanisation at all, but that does not mean that it is not used by real humans. For example, in Hungarian, one can use 2020. X. 2.
for 2 Oct 2020 (src). In Latin, the years are always written in Roman numerals and the day of month is sometimes too.
I don’t say that you are required to implement it, but please do consider implementing a flag for this within dayjs
codebase. Thanks.
@tukusejssirs Of course I know it's an important language. However, bundle extra logic to the main pack will significantly increase the bundle size, while the use is limited. In this case like many others, we recommend implementing it as a separate self-maintained plugin to make it fully supported.
Yes, ordinal only works for
Do
at present.Thanks for clarification. 😃
Cause it has too much different than other locales that we supported.
Well, indeed you don’t support romanisation at all, but that does not mean that it is not used by real humans. For example, in Hungarian, one can use
2020. X. 2.
for 2 Oct 2020 (src). In Latin, the years are always written in Roman numerals and the day of month is sometimes too.I don’t say that you are required to implement it, but please do consider implementing a flag for this within
dayjs
codebase. Thanks.
It's not true that the Hungarians writing months like XII. We can and allowed but never used. We use number: 1,2,3...12 I'm Hungarian. :-) The page what you linked says that the Hungarians might write the dates in 4 different format but actually we use only the 1st ,2nd and 3rd format. Of course the XII also right and acceptable for december but never used in such way.
For romcal, I need to add Latin locale to
dayjs
. Therefore I have some questions regarding this.feria secunda
for Monday), should I use a command as follows?A. using
dies
(used in the Ancient Rome):dies Solis
;dies Lunae
;dies Martis
;dies Mercurii
;dies Iovis
;dies Veneris
;dies Saturni
;B. using
ferias
(numbering days, starting with 1 for Sunday):feria prima
;feria secunda
;feria tertia
;feria quarta
;feria quinta
;feria sexta
;feria septima
;C. variation of the
feria
names, used in the RC Church (usesDominica
for Sunday andSabbato
for Saturday):Dominica
;feria secunda
;feria tertia
;feria quarta
;feria quinta
;feria sexta
;Sabbato
.Now, I need the C one only, but some other people might like some other names. If I implement this, I’d like to be as thorough as possible, so my question is: should I create three separate regions (like
la-va
for Vatican, i.e. the 3rd type of weekday names)? Or how else should I fix this?feria
names are used, one may shorten it by using Roman numerals (e.g.feria sexta
→fera VI
). I presume I should use these inweekdaysShort
, but I need a confirmation. Seldom, simply the Roman numerals are used (likeIV
), for which I could useweekdaysMin
.dayjs
include such a converter? Should I create a custom function withinla.js
?dayjs
with the output of Moment indayjs
tests, is it required to createla.js
locale in Moment first?