What is this date format?

Python 2, 123 bytes

a,b,c=map(int,input().split('-'))
for a,b,c in[[b,c,'big'],[b,a,'little'],[a,b,'middle']]:print(c+'-endian')*(a<13)*(b<32),

Try it online!


Python 2, less input parsing, 123 bytes

d=input()
for a,b,c in[[3,6,'big'],[3,0,'little'],[0,3,'middle']]:print(c+'-endian')*(int(d[a:a+2])<13)*(int(d[b:b+2])<32),

Try it online!


JavaScript (ES6), 121 119 118 112 bytes

Returns a space-delimited string with a trailing space.

s=>['big','little','middle'].map((v,i)=>[b<13&c<32,b<13&a<32,a<13][i]?v+'-endian ':'',[a,b,c]=s.split`-`).join``

How?

We split the input into a, b and c. Because the date is guaranteed to be valid, we know for sure that b is less than 32. Therefore, it's enough to test whether a is less than 13 to validate the middle-endian format. Little-endian and big-endian formats require b to be less than 13 and another test on a and c respectively to validate the day.

Hence the 3 tests:

  • Big-endian: b < 13 & c < 32
  • Little-endian: b < 13 & a < 32
  • Middle-endian: a < 13

Test cases

let f =

s=>['big','little','middle'].map((v,i)=>[b<13&c<32,b<13&a<32,a<13][i]?v+'-endian ':'',[a,b,c]=s.split`-`).join``

console.log(f("30-05-17")) // big-endian, little-endian
console.log(f("05-15-11")) // middle-endian
console.log(f("99-01-02")) // big-endian
console.log(f("12-11-31")) // big-endian, little-endian, middle-endian
console.log(f("02-31-33")) // middle-endian


Bash, 240 125 116 112 bytes

IFS=- read a b c<<<$1
d=-endian
((b<13))&&(((a<32))&&echo little$d;((c<32))&&echo big$d);((a<13))&&echo middle$d

Golfed.

Thanks to manatwork for some tips

Saved 9 bytes removing the verification for less than 32 in the middle-endian follwing Arnauld answer

Saved 4 bytes by using different variables instead of an array

Test it!

Tags:

Date

Code Golf