URL:
  <https://savannah.gnu.org/bugs/?61035>

                 Summary: NSDateFormatter truncates rather than rounding
                 Project: GNUstep
            Submitted by: lcampbel
            Submitted on: Thu 12 Aug 2021 10:45:12 PM UTC
                Category: None
                Severity: 3 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

This fails with gnustep but works on Mac OS X:

    NSDateFormatter *df;
    NSTimeInterval t = 650498989.396999955177;
    NSDate *d;
    NSString *s;

    df = [NSDateFormatter new];
    [df setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]];
    [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
    [df setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

    d = [[[NSDate alloc] initWithTimeIntervalSinceReferenceDate:t]
autorelease];
    s = [df stringFromDate:d];
    NSAssert([@"2021-08-12T22:09:49.397Z" isEqualToString:s], @"botch: should
get 2021-08-12T22:09:49.397Z but got %@", s);

with

2021-08-12 22:40:28.689 gnustep-base-tests[57679:57679]
gnustep-base-tests.m:610  Assertion failed in GnustepBaseTests(instance),
method nsdate.  botch: should get 2021-08-12T22:09:49.397Z but got
2021-08-12T22:09:49.396Z

because gnustep-base's NSDateFormatter apparently truncates fractional seconds
rather than rounding. (This is as of gnustep-base 1.27.0).




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?61035>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply via email to