Agent for information

Update,
I added the language used by the browser.

image

4 Likes

you are the best… already using that!

1 Like

Yes I use it to define the date format and for the translation

1 Like

I’m using it to translate my apps for users… time format might be tricky for big countries with many time zones

Hola Manu,

I have been working and improving my codes base on date format (sorting arrays) and this map and info were very useful to me.

Try to use the browser’s language is a good point and tool but I think that working with Endianness order is the final solution to date format sorting.

B – big-endian (year, month, day), e.g. 2016-04-22 // 2016.04.22 // 2016/04/22
L – little-endian (day, month, year), e.g. 22.04.2016 // 22-04-2016
M – middle-endian (month, day, year), e.g. 04/22/2016

Saludos!

2 Likes

Hi, Thank you for the information. I published a script on the topic of dates.
The idea is to convert the glide date (whatever the language and format) into a JS date to be able to easily sort or compare.

Yes I know, I shared my own code in that thread as well :rofl:

Now I have a new version able to sort any date array if the user has the following format:
1- mm/dd/yyyy
2- dd/mm/yyyy
3- dd-mm-yyyy
4- dd.mm.yyyy

I haven’t included other formats (e.g. yyyy-mm-dd) in order to not complicated the code but if I have to do it, I would use the Endianness code (B/M/L) to know the right date format used by user.

Feliz día

1 Like

I mean…

let f = s=>['B','L','M'].map((v,i)=>
  [b<13&c<32,b<13&a<32,a<13][i]?v+'':'',[a,b,c]=s.split`/`).join``

return(f(p5))  

In my case, all my date values are L – Little-endian therefore, my current date format is dd/mm/yyyy (day/month/year).

1 Like

Have you tried just passing the Glide date column to your YC function as a string, and then using new Date() to convert it to a JS Date object?

This is what I have been doing, and it seems to work fine, regardless of the date format. (Admittedly, I haven’t tested it with every possible format).

Hello @Darren_Murphy
Yes, anyway a YC column with a ‘date-time’ type necessarily arrives in string format (see the readme) so you have to do a ‘new date’. the problem is not the format (short, medium, long) but depending on the regions mm / dd / yyyy or dd / mm / yyyy or other

2 Likes

The problem here Darren is how Glide reads/handles the date, how the user sees it and how JS works with it.

If I’m in Latin America, my date format is dd/mm/yyyy and if this code is executed I will receive an error in my YC column although Glide shows it perfectly.

Example 1

t = '22/3/2021' ;      // March 22, 2021
return new Date(t)  // Returns “Invalid Date”

Example 2

t = '12/3/2021' ;     // March 12, 2021
return new Date(t) // Returns “Fri Dec 3 2021” - wrong date!

JS does not have a Date type as variable unfortunately, any Date value is treated as string :face_with_thermometer:

Saludos!

2 Likes

Hi friends,
there is an open discussion for the problem of dates, it is good if we continue on the right subject.

1 Like

Just to humour me, can you please try this and let me know the result?

  • Set your Glide date column to “medium” format, so it displays like “September 1, 2021, 1:18 AM”
  • Create a template column to lock in that format
  • Pass the template column to a YC column that tries to turn it into a date object using new Date()

That works fine for me, but maybe as you say there might be regional variations that break it. I’m curious to know.

PS. In my region, it’s also customary to use dd/mm/yyyy, but personally I would never use that format - or it’s ugly cousin mm/dd/yyyy. :wink:

1 Like

@Darren_Murphy

here you have:

1- Using en-US format (mm/dd/yyyy). I set my web browser to English and everything is ok:

2- Using sp-419 (format dd/mm/yyyy). I set my web browser to Spanish and problems appear:

Let me finish my code to find/handle several formats and I will share it to test it.

Feliz día!

in fact, nobody tested my code :stuck_out_tongue_winking_eye: :joy: :rofl:, because I solved the problem of the format according to the country dd/mm/yyyy mm/dd/yyyy, … and the format short, medium, long :stuck_out_tongue_winking_eye: :stuck_out_tongue_winking_eye:

2 Likes

Ufff … I didn’t know that :rofl:

Let me come back to my home and I will test your YC

ah, now I see. The problem is that new Date() can only parse a human readable date if it’s in in English, yes? Maybe you need to pre-process your dates by first passing them through a YC translate column - just kidding :rofl: :rofl:

If only everyone could agree that the only truly sensible date format is yyyy-mm-dd, then all these problems would evaporate.

Dates are such a PITA :nauseated_face:

3 Likes

We would need to start a campaign for this, get 100 million signatures maybe :rofl:

1 Like

hola @Manu.n

here my tests using your code, there is no good news, don’t hate me :innocent:

I’m using dd/mm/yyyy format (Spanish):

With short, it works fine:

With medium or long, an error appears :face_with_raised_eyebrow:

Am I doing anything wrong or JS is doing its job unfortunately?

Saludos!

Manu,

here using mm/dd/yyyy and English as language: :+1:

but with medium or long , an error appears again :cold_sweat:

I’m using your code
https://Date-Test-Array.manun2.repl.co