Re: NSLog displays inconsistent format for NSDate

2019-09-02 Thread Jean-Daniel via Cocoa-dev


> Le 1 sept. 2019 à 01:10, Carl Hoefs via Cocoa-dev  
> a écrit :
> 
> 
>> On Aug 31, 2019, at 2:51 AM, Allan Odgaard via Cocoa-dev 
>>  wrote:
>> 
>> On 31 Aug 2019, at 2:49, Carl Hoefs via Cocoa-dev wrote:
>> 
>>> Same result if I run it as a system daemon. So as you suggest it seems 
>>> there could be some sort of environment sensitivity going on. If only I 
>>> knew what env var to set in the shell... UTC really isn't what I'm looking 
>>> for.
>> 
>> The issue appears to be that `NSLog` sends your format string and arguments 
>> to the unified logging system, this is what Xcode and Console displays, and 
>> here you get dates formatted using the local time zone.
>> 
>> But it *also* does a simple `stringWithFormat:` and sends the result to 
>> standard error, at least when running in a terminal. This is where you are 
>> seeing a more crude formatting of the date which is not adjusted to the 
>> local time zone.
>> 
>> Open a new tab in your terminal, in that tab run this command:
>> 
>>  log stream|grep 'Configured date'
>> 
>> Now run your executable, and in the tab where it is running, you should see 
>> the UTC date, but in the tab where you are watching the log stream, you get 
>> the local date.
>> ___
>> 
> 
> Thanks for the input! 
> 
> I realized this is occurring because I'm allowing macOS to generate the date 
> string according to its whims. If I do the string generation, then I can get 
> consistent results. So I added the following line to my code:
> 
>NSString *dateString = [NSDateFormatter 
> localizedStringFromDate:configuredDate dateStyle:NSDateFormatterFullStyle 
> timeStyle:NSDateFormatterLongStyle];
> 
> and now I get a standardized string I can at least can live with, valid for 
> all situations:
> 
> Configured date: Saturday, August 31, 2019 at 3:55:02 PM PDT
> 

Note that your output is still Local dependent and can change from on system to 
an other.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSLog displays inconsistent format for NSDate

2019-08-31 Thread Alex Zavatone via Cocoa-dev
Use an NSDateFormatter.  Use a format string with at the end ZZZ or  if you 
want the time zone offset added.




> On Aug 20, 2019, at 2:50 PM, Carl Hoefs via Cocoa-dev 
>  wrote:
> 
> When printing out an NSDate using NSLog from within Xcode I get:
> 
> "Tue Aug 20 12:32:40 2019"
> 
> When the same program is run from within a shell (bash) window:
> 
> "2019-08-20 19:32:48 +"
> 
> Is the NSDate output format somehow determined by the environment? My system 
> is set to Local Time Zone (America/Los_Angeles (PDT) offset -25200 
> (Daylight)).
> 
> A code snippet that reproduces the issue follows. 
> 
> -Carl
> 
> 
> 
> - (void) testDate
> {
>NSCalendar *calendar = [NSCalendar currentCalendar];
>unsigned unitFlags = 
> NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitTimeZone;
>NSDateComponents *dateComponents = [calendar components:unitFlags 
> fromDate:[NSDate date]];
>dateComponents.timeZone = NSTimeZone.localTimeZone;
>NSDate *configuredDate = [calendar dateFromComponents:dateComponents];
>NSLog(@"Configured date: %@",configuredDate);
> }
> 
> Xcode:
> 2019-08-20 12:32:40.828863-0700 tester[3926:1353] Configured date: Tue Aug 20 
> 12:32:40 2019
> 
> Shell:
> 2019-08-20 12:33:08.356 tester[3928:1359] Configured date: 2019-08-20 
> 19:32:48 +
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to z...@mac.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSLog displays inconsistent format for NSDate

2019-08-31 Thread Carl Hoefs via Cocoa-dev


> On Aug 31, 2019, at 2:51 AM, Allan Odgaard via Cocoa-dev 
>  wrote:
> 
> On 31 Aug 2019, at 2:49, Carl Hoefs via Cocoa-dev wrote:
> 
>> Same result if I run it as a system daemon. So as you suggest it seems there 
>> could be some sort of environment sensitivity going on. If only I knew what 
>> env var to set in the shell... UTC really isn't what I'm looking for.
> 
> The issue appears to be that `NSLog` sends your format string and arguments 
> to the unified logging system, this is what Xcode and Console displays, and 
> here you get dates formatted using the local time zone.
> 
> But it *also* does a simple `stringWithFormat:` and sends the result to 
> standard error, at least when running in a terminal. This is where you are 
> seeing a more crude formatting of the date which is not adjusted to the local 
> time zone.
> 
> Open a new tab in your terminal, in that tab run this command:
> 
>   log stream|grep 'Configured date'
> 
> Now run your executable, and in the tab where it is running, you should see 
> the UTC date, but in the tab where you are watching the log stream, you get 
> the local date.
> ___
> 

Thanks for the input! 

I realized this is occurring because I'm allowing macOS to generate the date 
string according to its whims. If I do the string generation, then I can get 
consistent results. So I added the following line to my code:

NSString *dateString = [NSDateFormatter 
localizedStringFromDate:configuredDate dateStyle:NSDateFormatterFullStyle 
timeStyle:NSDateFormatterLongStyle];

and now I get a standardized string I can at least can live with, valid for all 
situations:

Configured date: Saturday, August 31, 2019 at 3:55:02 PM PDT

-Carl

P.S.: NSDateFormatter & friends are, shall I say, squirrelly beasts, best left 
undisturbed, hiding under the rock ...

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSLog displays inconsistent format for NSDate

2019-08-31 Thread Allan Odgaard via Cocoa-dev

On 31 Aug 2019, at 2:49, Carl Hoefs via Cocoa-dev wrote:

Same result if I run it as a system daemon. So as you suggest it seems 
there could be some sort of environment sensitivity going on. If only 
I knew what env var to set in the shell... UTC really isn't what I'm 
looking for.


The issue appears to be that `NSLog` sends your format string and 
arguments to the unified logging system, this is what Xcode and Console 
displays, and here you get dates formatted using the local time zone.


But it *also* does a simple `stringWithFormat:` and sends the result to 
standard error, at least when running in a terminal. This is where you 
are seeing a more crude formatting of the date which is not adjusted to 
the local time zone.


Open a new tab in your terminal, in that tab run this command:

log stream|grep 'Configured date'

Now run your executable, and in the tab where it is running, you should 
see the UTC date, but in the tab where you are watching the log stream, 
you get the local date.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSLog displays inconsistent format for NSDate

2019-08-30 Thread Carl Hoefs via Cocoa-dev
Outside of Xcode, when I run the program (a "Command line tool") directly from 
the bash shell, it prints out in UTC "unixy" format:

2019-08-31 01:00:01 +

...but at the same time it gets logged in the Console log as:

Fri Aug 30 18:00:01 2019

Same result if I run it as a system daemon. So as you suggest it seems there 
could be some sort of environment sensitivity going on. If only I knew what env 
var to set in the shell... UTC really isn't what I'm looking for.

-Carl


> On Aug 30, 2019, at 5:20 PM, Uli Kusterer  
> wrote:
> 
> Wildly guessing here, but could be that NSLog uses different implementations 
> depending on how it was launched. It could be using os_log() under the hood, 
> which doesn't necessarily format all parameters right away, but rather just 
> sends them to the logging system, which then formats it?
> 
> Cheers,
> -- Uli Kusterer
> "The Witnesses of TeachText are everywhere..."
> http://www.zathras.de
> 
>> On 20. Aug 2019, at 21:50, Carl Hoefs via Cocoa-dev 
>>  wrote:
>> 
>> When printing out an NSDate using NSLog from within Xcode I get:
>> 
>> "Tue Aug 20 12:32:40 2019"
>> 
>> When the same program is run from within a shell (bash) window:
>> 
>> "2019-08-20 19:32:48 +"
>> 
>> Is the NSDate output format somehow determined by the environment? My system 
>> is set to Local Time Zone (America/Los_Angeles (PDT) offset -25200 
>> (Daylight)).
>> 
>> A code snippet that reproduces the issue follows. 
>> 
>> -Carl
> 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSLog displays inconsistent format for NSDate

2019-08-30 Thread Uli Kusterer via Cocoa-dev
Wildly guessing here, but could be that NSLog uses different implementations 
depending on how it was launched. It could be using os_log() under the hood, 
which doesn't necessarily format all parameters right away, but rather just 
sends them to the logging system, which then formats it?

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de

> On 20. Aug 2019, at 21:50, Carl Hoefs via Cocoa-dev 
>  wrote:
> 
> When printing out an NSDate using NSLog from within Xcode I get:
> 
> "Tue Aug 20 12:32:40 2019"
> 
> When the same program is run from within a shell (bash) window:
> 
> "2019-08-20 19:32:48 +"
> 
> Is the NSDate output format somehow determined by the environment? My system 
> is set to Local Time Zone (America/Los_Angeles (PDT) offset -25200 
> (Daylight)).
> 
> A code snippet that reproduces the issue follows. 
> 
> -Carl

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSLog displays inconsistent format for NSDate

2019-08-20 Thread Gary L. Wade via Cocoa-dev
If you want to output a date in a predictable format, you should use a date 
formatter.  When I ran a sample app under the simulator for tvOS 13 in Xcode 11 
beta 5, I got these results for the specified locales:

2019-08-20 19:51:05.637667-0700 TestDateDescription[32894:2579867] ar_AE: The 
date is now 2019-08-21 02:51:05 +
2019-08-20 19:51:42.350744-0700 TestDateDescription[32899:2580909] fr_FR: The 
date is now 2019-08-21 02:51:42 +
2019-08-20 19:52:13.121429-0700 TestDateDescription[32905:2581496] en_US: The 
date is now 2019-08-21 02:52:13 +

This was the line of Swift I used:

NSLog("%@: The date is now %@", Locale.current.identifier, NSDate())

For a predictable format in logs, I’d suggest using NSISO8601DateFormatter.
--
Gary L. Wade
http://www.garywade.com/ 

> On Aug 20, 2019, at 12:50 PM, Carl Hoefs via Cocoa-dev 
>  wrote:
> 
> When printing out an NSDate using NSLog from within Xcode I get:
> 
> "Tue Aug 20 12:32:40 2019"
> 
> When the same program is run from within a shell (bash) window:
> 
> "2019-08-20 19:32:48 +"
> 
> Is the NSDate output format somehow determined by the environment? My system 
> is set to Local Time Zone (America/Los_Angeles (PDT) offset -25200 
> (Daylight)).
> 
> A code snippet that reproduces the issue follows. 
> 
> -Carl
> 
> 
> 
> - (void) testDate
> {
>NSCalendar *calendar = [NSCalendar currentCalendar];
>unsigned unitFlags = 
> NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitTimeZone;
>NSDateComponents *dateComponents = [calendar components:unitFlags 
> fromDate:[NSDate date]];
>dateComponents.timeZone = NSTimeZone.localTimeZone;
>NSDate *configuredDate = [calendar dateFromComponents:dateComponents];
>NSLog(@"Configured date: %@",configuredDate);
> }
> 
> Xcode:
> 2019-08-20 12:32:40.828863-0700 tester[3926:1353] Configured date: Tue Aug 20 
> 12:32:40 2019
> 
> Shell:
> 2019-08-20 12:33:08.356 tester[3928:1359] Configured date: 2019-08-20 
> 19:32:48 +
> 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSLog displays inconsistent format for NSDate

2019-08-20 Thread Carl Hoefs via Cocoa-dev
When printing out an NSDate using NSLog from within Xcode I get:

"Tue Aug 20 12:32:40 2019"

When the same program is run from within a shell (bash) window:

"2019-08-20 19:32:48 +"

Is the NSDate output format somehow determined by the environment? My system is 
set to Local Time Zone (America/Los_Angeles (PDT) offset -25200 (Daylight)).

A code snippet that reproduces the issue follows. 

-Carl



- (void) testDate
{
NSCalendar *calendar = [NSCalendar currentCalendar];
unsigned unitFlags = 
NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitTimeZone;
NSDateComponents *dateComponents = [calendar components:unitFlags 
fromDate:[NSDate date]];
dateComponents.timeZone = NSTimeZone.localTimeZone;
NSDate *configuredDate = [calendar dateFromComponents:dateComponents];
NSLog(@"Configured date: %@",configuredDate);
}

Xcode:
2019-08-20 12:32:40.828863-0700 tester[3926:1353] Configured date: Tue Aug 20 
12:32:40 2019

Shell:
2019-08-20 12:33:08.356 tester[3928:1359] Configured date: 2019-08-20 19:32:48 
+

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com