#import <Foundation/Foundation.h>

int main() {
  NSAutoreleasePool *pool = [NSAutoreleasePool new];

  NSDateFormatter *df = [[NSDateFormatter new] autorelease];
  [df setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
  [df setTimeStyle:NSDateFormatterMediumStyle];
  [df setDateStyle:NSDateFormatterMediumStyle];
  [df setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:118800];
  NSString *dateStr = [df stringFromDate:date];
  NSString *refStr = @"Jan 2, 2001, 9:00:00 AM";
  NSLog(@"nsDateFormatter test 1: dateStr = %@, refStr = %@", dateStr, refStr);
  if (! [dateStr isEqualToString:refStr]) {
      NSLog(@"ERROR: Strings do not match");
      [pool release];
      return 1;
  }
    
  df = [[NSDateFormatter new] autorelease];
  [df setDateFormat:@"yyyyMMddHHmmss"];
  [df setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
  dateStr = [df stringFromDate:date];
  refStr = @"20010102090000";
  NSLog(@"nsDateFormatter test 2: dateStr = %@, refStr = %@", dateStr, refStr);
  if (! [dateStr isEqualToString:refStr]) {
      NSLog(@"ERROR: Strings do not match");
      [pool release];
      return 1;
  }

  NSLog(@"Test passed");
  [pool release];
  return 0;
}
