discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDateFormatter SetDateStyle / setTimeStyle not working


From: Stefan Bidigaray
Subject: Re: NSDateFormatter SetDateStyle / setTimeStyle not working
Date: Sat, 26 Aug 2017 11:36:57 -0400

Hi Edwin,
There must be something wrong with your installation. I created the attached tests (simply copied yours) and I'm getting the correct output. I even set the locale to nl_BE, in case that was the problem.

My output was:
2017-08-26 11:28:59.892 a.out[2724:2724] the date as date object             2017-08-26 11:28:59 -0400
2017-08-26 11:28:59.893 a.out[2724:2724] Dateformatter defaults
2017-08-26 11:28:59.893 a.out[2724:2724]   DateFormatter timezone: America/New_York
2017-08-26 11:28:59.893 a.out[2724:2724]   DateFormatter locale: en_US
2017-08-26 11:28:59.893 a.out[2724:2724]   DateFormatter datestyle: 0
2017-08-26 11:28:59.893 a.out[2724:2724]   DateFormatter timestyle: 0
2017-08-26 11:28:59.893 a.out[2724:2724]   Date formatted with defaults 20170826 11:28 AM
2017-08-26 11:28:59.914 a.out[2724:2724] DateFormatter: Date -> NoStyle, Time -> MediumStyle
2017-08-26 11:28:59.914 a.out[2724:2724]   DateFormatter timezone: America/New_York
2017-08-26 11:28:59.914 a.out[2724:2724]   DateFormatter locale: nl_BE
2017-08-26 11:28:59.914 a.out[2724:2724]   DateFormatter datestyle: 0
2017-08-26 11:28:59.914 a.out[2724:2724]   DateFormatter timestyle: 2
2017-08-26 11:28:59.914 a.out[2724:2724]   Date formatted with style 11:28:59
2017-08-26 11:28:59.914 a.out[2724:2724] DateFormatter: Date -> LongStyle, Time -> LongStyle
2017-08-26 11:28:59.914 a.out[2724:2724]   DateFormatter timezone: America/New_York
2017-08-26 11:28:59.914 a.out[2724:2724]   DateFormatter locale: nl_BE
2017-08-26 11:28:59.914 a.out[2724:2724]   DateFormatter datestyle: 3
2017-08-26 11:28:59.914 a.out[2724:2724]   DateFormatter timestyle: 3
2017-08-26 11:28:59.924 a.out[2724:2724]   Date formatted with style 26 augustus 2017 11:28:59 GMT-4

You might want to you libicudata.so file and make sure it is huge! That's the "library" (it's more of a resource file) where all this Unicode stuff resides. There's a chance yours was not built with all the resources. As an example, here's mine:
$ ls -lh /usr/lib/x86_64-linux-gnu/libicudata.so.55.1
-rw-r--r-- 1 root root 25M May  2 09:50 /usr/lib/x86_64-linux-gnu/libicudata.so.55.1

As you can see, it's 25MB in size.

On Sat, Aug 26, 2017 at 8:55 AM, Stefan Bidigaray <address@hidden> wrote:
Hmm, that does seem stage. It should all be working. I'm sure the problem is not the FreeBSD source, David does a pretty good job keeping those updated.

I'll test it on my end a bit to try to figure it out.

On Aug 26, 2017 00:46, "Edwin Ancaer" <address@hidden> wrote:
Fred, Stefan,

Indeed, the instruction [format lenient] returns 1, independant of setting the value with 
[format  setLenient: NO] and  [format setLenient: YES].

I'm sure I saw libicu mentioned in the dependencies for gnustep, and given the definition of isLenient in NSDatformatter.m and the fact that I got 1 from isLenient, I supposed that GS_USE_ICU was 1: return NO resulting in the value 1 seems illogical.

- (BOOL) isLenient
{
#if GS_USE_ICU == 1
return (BOOL)udat_isLenient (internal->_formatter);
#else
return NO;
#endif
}

But thinking of it, this is the source from https://github.com/gnustep/libs-base/blob/master/Source/NSDateFormatter.m., I've got no idea were FreeBSD is getting its sources. I will have to look into the freebsd ports mechanism to find out, just to be sure. Or try the debugger, to see what is really going on.

Concerning the locale, the value for systemlocale is "en_US_posix", the default locale is "nl_BE",and the locale returned from the NSDateFormatter is also "nl_BE". But I admit, the returned values  do not look correctly formatted either. 

Again, maybe the debugger is the best way to find out what is going wrong.


Thanks for your anwers already, I'll see if I can find out more about this. Or give up, and just use format strings....

Kind regards,

Edwin

2017-08-25 15:21 GMT+02:00 Stefan Bidigaray <address@hidden>:
Based on your previous posts, it sounds like your current locale is en_US_POSIX. Can you verify that by checking the output of [NSDateFormatter -locale]? This locale outputs the same date string regardless of the style.

You can set the formatter's locale with -setLocale: before any calls to -stringFromDate:.

On Aug 25, 2017 00:38, "Edwin Ancaer" <address@hidden> wrote:
Hello,

I hardly dare to suggest it, but I have got the impression that the methods setDateStyle & setTimeStyle have no influence on the result of the method stringFromDate, as you can see in the examples below.

Is it me, again not having understood the workings of these classes completely, or is there really a problem?

I'm on FreeBSD 11.0, with gnustep installed from the ports.

Examples:

  NSDate* d = [NSDate date];  
  NSLog(@"the date as date object             %@", d);
    
2017-08-25 06:20:32.673 TM1[1295:100101] the date as date object             2017-08-25 06:20:32 +0200        


  NSDateFormatter* format = [[NSDateFormatter alloc] init];
  NSLog(@"Dateformatter defaults");
  NSLog(@"  DateFormatter timezone: %@", [format timeZone]);
  NSLog(@"  DateFormatter locale: %@", [format locale]);
  NSLog(@"  DateFormatter datestyle: %u", [format dateStyle]);
  NSLog(@"  DateFormatter timestyle: %u", [format timeStyle]);
  NSLog(@"  Date formatted with defaults      %@", [format stringFromDate: d]);

2017-08-25 06:20:32.695 TM1[1295:100101] Dateformatter defaults
2017-08-25 06:20:32.703 TM1[1295:100101]   DateFormatter timezone: Europe/Brussels
2017-08-25 06:20:32.711 TM1[1295:100101]   DateFormatter locale: nl_BE
2017-08-25 06:20:32.719 TM1[1295:100101]   DateFormatter datestyle: 0
2017-08-25 06:20:32.727 TM1[1295:100101]   DateFormatter timestyle: 0
2017-08-25 06:20:32.736 TM1[1295:100101]   Date formatted with defaults      20170825 06:20 a.m.

 
  [format setDateStyle: NSDateFormatterNoStyle];
  [format setTimeStyle: NSDateFormatterMediumStyle];
  NSLog(@"DateFormatter: Date -> NoStyle, Time -> MediumStyle");
  NSLog(@"  DateFormatter timezone: %@", [format timeZone]);
  NSLog(@"  DateFormatter locale: %@", [format locale]);
  NSLog(@"  DateFormatter datestyle: %u", [format dateStyle]);
  NSLog(@"  DateFormatter timestyle: %u", [format timeStyle]);
  NSLog(@"  Date formatted with style         %@", [format stringFromDate: d]);
 
2017-08-25 06:20:32.745 TM1[1295:100101] DateFormatter: Date -> NoStyle, Time -> MediumStyle
2017-08-25 06:20:32.754 TM1[1295:100101]   DateFormatter timezone: Europe/Brussels
2017-08-25 06:20:32.763 TM1[1295:100101]   DateFormatter locale: nl_BE
2017-08-25 06:20:32.773 TM1[1295:100101]   DateFormatter datestyle: 0
2017-08-25 06:20:32.783 TM1[1295:100101]   DateFormatter timestyle: 2
2017-08-25 06:20:32.794 TM1[1295:100101]   Date formatted with style         20170825 06:20 a.m.


  [format setDateStyle: NSDateFormatterLongStyle];
  [format setTimeStyle: NSDateFormatterLongStyle];
  NSLog(@"DateFormatter: Date -> LongStyle, Time -> LongStyle");
  NSLog(@"  DateFormatter timezone: %@", [format timeZone]);
  NSLog(@"  DateFormatter locale: %@", [format locale]);
  NSLog(@"  DateFormatter datestyle: %u", [format dateStyle]);
  NSLog(@"  DateFormatter timestyle: %u", [format timeStyle]);
  NSLog(@"  Date formatted with style         %@", [format stringFromDate: d]);  

2017-08-25 06:20:32.809 TM1[1295:100101] DateFormatter: Date -> LongStyle, Time -> LongdiumStyle
2017-08-25 06:20:32.825 TM1[1295:100101]   DateFormatter timezone: Europe/Brussels
2017-08-25 06:20:32.838 TM1[1295:100101]   DateFormatter locale: nl_BE
2017-08-25 06:20:32.853 TM1[1295:100101]   DateFormatter datestyle: 3
2017-08-25 06:20:32.867 TM1[1295:100101]   DateFormatter timestyle: 3
2017-08-25 06:20:32.881 TM1[1295:100101]   Date formatted with style         20170825 06:20 a.m.

Could someone tell me what the problem is here?

Thanks,

Edwin Ancaer

_______________________________________________
Discuss-gnustep mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/discuss-gnustep



Attachment: test_nsdateformatter.m
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]