ios - Know when to use short or full month names -
under ios 7 or 8, stock calendar app have been unable figure out.
under locales, such en_us
, calendar app shows short (3-letter) month names.
under other locales, such de_de
, calendar app shows total month names. interestingly, locale en_de
shows short month names seems tied language more part format.
what can't figure out how know month format use.
regardless of device's locale, nsdateformatter standaloneshortmonthsymbols
gives me 3-letter month names , nsdateformatter standalonemonthsymbols
gives me total month names.
is tried:
nsstring *monthformat = [nsdateformatter dateformatfromtemplate:@"lll" options:0 locale:[nslocale currentlocale]];
and gives same lll
both en_us
, de_de
.
looking @ nslocale
there doesn't appear value determines whether utilize short or total month names.
there doesn't appear in nscalendar
, nsdateformatter
, or nslocale
help determine month format use.
does have thought how create determination?
update:
i thought found solution doesn't work locales tried. ran next code various locales see if find in mutual between locales show short , long months names in calendar app:
nslocale *locale = [nslocale currentlocale]; nsstring *locid = [locale localeidentifier]; nslog(@"locale = %@", locid); nsdateformatter *formatter = [[nsdateformatter alloc] init]; nslog(@"monthsymbols = %@", [formatter monthsymbols]); nslog(@"shortmonthsymbols = %@", [formatter shortmonthsymbols]); nslog(@"veryshortmonthsymbols = %@", [formatter veryshortmonthsymbols]); nslog(@"monthstandalonesymbols = %@", [formatter standalonemonthsymbols]); nslog(@"shortstandalonemonthsymbols = %@", [formatter shortstandalonemonthsymbols]); nslog(@"veryshortstandalonemonthsymbols = %@", [formatter veryshortstandalonemonthsymbols]); nsdate *date = [nsdate date]; [formatter setdatestyle:nsdateformattershortstyle]; nslog(@"short date style: %@", [formatter stringfromdate:date]); [formatter setdatestyle:nsdateformattermediumstyle]; nslog(@"medium date style: %@", [formatter stringfromdate:date]); [formatter setdatestyle:nsdateformatterlongstyle]; nslog(@"long date style: %@", [formatter stringfromdate:date]); [formatter setdatestyle:nsdateformatterfullstyle]; nslog(@"full date style: %@", [formatter stringfromdate:date]); [formatter setdatestyle:nsdateformatternostyle]; [formatter setdateformat:@"m"]; nslog(@"m date format: %@", [formatter stringfromdate:date]); [formatter setdateformat:@"mm"]; nslog(@"mm date format: %@", [formatter stringfromdate:date]); [formatter setdateformat:@"mmm"]; nslog(@"mmm date format: %@", [formatter stringfromdate:date]); [formatter setdateformat:@"mmmm"]; nslog(@"mmmm date format: %@", [formatter stringfromdate:date]); [formatter setdateformat:@"mmmmm"]; nslog(@"mmmmm date format: %@", [formatter stringfromdate:date]); [formatter setdateformat:@"l"]; nslog(@"l date format: %@", [formatter stringfromdate:date]); [formatter setdateformat:@"ll"]; nslog(@"ll date format: %@", [formatter stringfromdate:date]); [formatter setdateformat:@"lll"]; nslog(@"lll date format: %@", [formatter stringfromdate:date]); [formatter setdateformat:@"llll"]; nslog(@"llll date format: %@", [formatter stringfromdate:date]); [formatter setdateformat:@"lllll"]; nslog(@"lllll date format: %@", [formatter stringfromdate:date]);
i had tested en_us
, en_gb
, es_es
, de_de
, fr_fr
, , it_it
. french , high german locales show total month name in calendar app while rest show short name.
the 1 thing looked promising test code french , high german locales have period @ end of shortmonthsymbols
.
so ran next code find locales utilize punctuation in short month symbols , don't:
nsmutablearray *hasdot = [[nsmutablearray alloc] init]; nsmutablearray *nodot = [[nsmutablearray alloc] init]; nscharacterset *letters = [nscharacterset lettercharacterset]; nsarray *locales = [nslocale availablelocaleidentifiers]; (nsstring *locid in locales) { nslocale *locale = [nslocale localewithlocaleidentifier:locid]; nsdateformatter *formatter = [[nsdateformatter alloc] init]; [formatter setlocale:locale]; nsarray *shortnames = [formatter shortmonthsymbols]; //nslog(@"locale: %@, short names: %@", locid, shortnames[10]); nsstring *nov = shortnames[10]; unichar char1 = [nov characteratindex:0]; unichar charn = [nov characteratindex:nov.length - 1]; if ([letters characterismember:char1] && [letters characterismember:charn]) { [nodot addobject:locid]; } else { [hasdot addobject:locid]; } } nslog(@"no dot: %@", [nodot sortedarrayusingselector:@selector(compare:)]); nslog(@"has dot: %@", [hasdot sortedarrayusingselector:@selector(compare:)]);
scanning through results saw dutch locales used period in short month symbols. quick test of calendar app revealed calendar app showed short month names when device set dutch (nl_nl
). ugh.
update 2:
i've tested few more locales. next show long month names:
fr_fr, de_de, ru_ru, sv_se (actually locales each of these languages)
the next (and i'm sure many more) show short month:
en_us, en_gb, es_es, it_it, nl_nl, ca_es, uk_ua, ro_ro (actually locales each of these languages)
once every often, there comes question worth looking into. rick, debugged calendar app (can done using attaching mobilecal process). comes downwards eventkitui`currentlocalerequiresunabbrevatedmonthnames
answers desired question.
let's @ disassembly:
eventkitui`currentlocalerequiresunabbrevatedmonthnames: 0x102c6bec7: pushq %rbp 0x102c6bec8: movq %rsp, %rbp 0x102c6becb: pushq %r15 0x102c6becd: pushq %r14 0x102c6becf: pushq %rbx 0x102c6bed0: subq $0xb8, %rsp 0x102c6bed7: movq 0x14a3aa(%rip), %r15 ; (void *)0x0000000104e93070: __stack_chk_guard 0x102c6bede: movq (%r15), %rax 0x102c6bee1: movq %rax, -0x20(%rbp) 0x102c6bee5: cmpq $0x0, 0x1c01fb(%rip) ; currentlocalerequiresunabbrevatedmonthnames.usesfulllengthmonthnames + 6 0x102c6beed: je 0x102c6beff ; currentlocalerequiresunabbrevatedmonthnames + 56 0x102c6beef: movb 0x1c01eb(%rip), %al ; currentlocalerequiresunabbrevatedmonthnames.haschecked 0x102c6bef5: xorb $0x1, %al 0x102c6bef7: testb $0x1, %al 0x102c6bef9: je 0x102c6c0d6 ; currentlocalerequiresunabbrevatedmonthnames + 527 0x102c6beff: movq 0x1b583a(%rip), %rdi ; (void *)0x00000001025dae58: nslocale 0x102c6bf06: movq 0x1aef23(%rip), %rsi ; "currentlocale" 0x102c6bf0d: movq 0x14a524(%rip), %r14 ; (void *)0x0000000104945000: objc_msgsend 0x102c6bf14: callq *%r14 0x102c6bf17: movq %rax, %rdi 0x102c6bf1a: callq 0x102d29920 ; symbol stub for: objc_retainautoreleasedreturnvalue 0x102c6bf1f: movq %rax, %rbx 0x102c6bf22: movq 0x14a227(%rip), %rax ; (void *)0x00000001025a3cd8: nslocalelanguagecode 0x102c6bf29: movq (%rax), %rdx 0x102c6bf2c: movq 0x1ae12d(%rip), %rsi ; "objectforkey:" 0x102c6bf33: movq %rbx, %rdi 0x102c6bf36: callq *%r14 0x102c6bf39: movq %rax, %rdi 0x102c6bf3c: callq 0x102d29920 ; symbol stub for: objc_retainautoreleasedreturnvalue 0x102c6bf41: movq %rax, %r14 0x102c6bf44: movq %rbx, %rdi 0x102c6bf47: callq *0x14a4f3(%rip) ; (void *)0x00000001049429b0: objc_release 0x102c6bf4d: movq 0x1c0194(%rip), %rdi ; __languagesrequiringunabbreviatedmonthnames 0x102c6bf54: testq %rdi, %rdi 0x102c6bf57: jne 0x102c6c0b0 ; currentlocalerequiresunabbrevatedmonthnames + 489 0x102c6bf5d: leaq 0x15425c(%rip), %rax ; @"ru" 0x102c6bf64: movq %rax, -0xd0(%rbp) 0x102c6bf6b: leaq 0x1524ce(%rip), %rax ; @"de" 0x102c6bf72: movq %rax, -0xc8(%rbp) 0x102c6bf79: leaq 0x154260(%rip), %rax ; @"fr" 0x102c6bf80: movq %rax, -0xc0(%rbp) 0x102c6bf87: leaq 0x154272(%rip), %rax ; @"fi" 0x102c6bf8e: movq %rax, -0xb8(%rbp) 0x102c6bf95: leaq 0x154284(%rip), %rax ; @"pt" 0x102c6bf9c: movq %rax, -0xb0(%rbp) 0x102c6bfa3: leaq 0x154296(%rip), %rax ; @"no" 0x102c6bfaa: movq %rax, -0xa8(%rbp) 0x102c6bfb1: leaq 0x1542a8(%rip), %rax ; @"nb" 0x102c6bfb8: movq %rax, -0xa0(%rbp) 0x102c6bfbf: leaq 0x1542ba(%rip), %rax ; @"nn" 0x102c6bfc6: movq %rax, -0x98(%rbp) 0x102c6bfcd: leaq 0x1542cc(%rip), %rax ; @"sv" 0x102c6bfd4: movq %rax, -0x90(%rbp) 0x102c6bfdb: leaq 0x1542de(%rip), %rax ; @"he" 0x102c6bfe2: movq %rax, -0x88(%rbp) 0x102c6bfe9: leaq 0x1542f0(%rip), %rax ; @"th" 0x102c6bff0: movq %rax, -0x80(%rbp) 0x102c6bff4: leaq 0x154305(%rip), %rax ; @"hi" 0x102c6bffb: movq %rax, -0x78(%rbp) 0x102c6bfff: leaq 0x15431a(%rip), %rax ; @"bn" 0x102c6c006: movq %rax, -0x70(%rbp) 0x102c6c00a: leaq 0x15432f(%rip), %rax ; @"mr" 0x102c6c011: movq %rax, -0x68(%rbp) 0x102c6c015: leaq 0x154344(%rip), %rax ; @"ur" 0x102c6c01c: movq %rax, -0x60(%rbp) 0x102c6c020: leaq 0x154359(%rip), %rax ; @"te" 0x102c6c027: movq %rax, -0x58(%rbp) 0x102c6c02b: leaq 0x15436e(%rip), %rax ; @"ta" 0x102c6c032: movq %rax, -0x50(%rbp) 0x102c6c036: leaq 0x154383(%rip), %rax ; @"gu" 0x102c6c03d: movq %rax, -0x48(%rbp) 0x102c6c041: leaq 0x154398(%rip), %rax ; @"kn" 0x102c6c048: movq %rax, -0x40(%rbp) 0x102c6c04c: leaq 0x1543ad(%rip), %rax ; @"ml" 0x102c6c053: movq %rax, -0x38(%rbp) 0x102c6c057: leaq 0x1543c2(%rip), %rax ; @"ne" 0x102c6c05e: movq %rax, -0x30(%rbp) 0x102c6c062: leaq 0x1543d7(%rip), %rax ; @"pa" 0x102c6c069: movq %rax, -0x28(%rbp) 0x102c6c06d: movq 0x1b55ec(%rip), %rdi ; (void *)0x00000001025d9cd8: nsarray 0x102c6c074: movq 0x1ae5cd(%rip), %rsi ; "arraywithobjects:count:" 0x102c6c07b: leaq -0xd0(%rbp), %rdx 0x102c6c082: movl $0x16, %ecx 0x102c6c087: callq *0x14a3ab(%rip) ; (void *)0x0000000104945000: objc_msgsend 0x102c6c08d: movq %rax, %rdi 0x102c6c090: callq 0x102d29920 ; symbol stub for: objc_retainautoreleasedreturnvalue 0x102c6c095: movq 0x1c004c(%rip), %rdi ; __languagesrequiringunabbreviatedmonthnames 0x102c6c09c: movq %rax, 0x1c0045(%rip) ; __languagesrequiringunabbreviatedmonthnames 0x102c6c0a3: callq *0x14a397(%rip) ; (void *)0x00000001049429b0: objc_release 0x102c6c0a9: movq 0x1c0038(%rip), %rdi ; __languagesrequiringunabbreviatedmonthnames 0x102c6c0b0: movq 0x1ae6c1(%rip), %rsi ; "containsobject:" 0x102c6c0b7: movq %r14, %rdx 0x102c6c0ba: callq *0x14a378(%rip) ; (void *)0x0000000104945000: objc_msgsend 0x102c6c0c0: movb %al, 0x1c001b(%rip) ; currentlocalerequiresunabbrevatedmonthnames.usesfulllengthmonthnames 0x102c6c0c6: movb $0x1, 0x1c0013(%rip) ; __overlaycalendargeneration + 7 0x102c6c0cd: movq %r14, %rdi 0x102c6c0d0: callq *0x14a36a(%rip) ; (void *)0x00000001049429b0: objc_release 0x102c6c0d6: movb 0x1c0005(%rip), %al ; currentlocalerequiresunabbrevatedmonthnames.usesfulllengthmonthnames 0x102c6c0dc: movq (%r15), %rcx 0x102c6c0df: cmpq -0x20(%rbp), %rcx 0x102c6c0e3: jne 0x102c6c0f3 ; currentlocalerequiresunabbrevatedmonthnames + 556 0x102c6c0e5: addq $0xb8, %rsp 0x102c6c0ec: popq %rbx 0x102c6c0ed: popq %r14 0x102c6c0ef: popq %r15 0x102c6c0f1: popq %rbp 0x102c6c0f2: retq 0x102c6c0f3: callq 0x102d29a1c ; symbol stub for: __stack_chk_fail
as can see, creates array of locales require unabbreviated month names. compares if current locale 1 of these locales.
hardcoded in code.
for abbreviated months, uses lll
format (as seen in eventkitui`calstringformonth
), , unabbreviated months, uses llll
format (as seen in eventkitui`callongstringformonth
).
cheers
ios objective-c nsdateformatter nslocale
No comments:
Post a Comment