File: basic.m

package info (click to toggle)
gnustep-corebase 0.1.1%2B20230710-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,608 kB
  • sloc: ansic: 25,359; objc: 4,347; cpp: 75; xml: 49; makefile: 24; sh: 7
file content (56 lines) | stat: -rw-r--r-- 1,908 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "CoreFoundation/CFDateFormatter.h"
#include "CoreFoundation/CFTimeZone.h"
#include "../CFTesting.h"

int main (void)
{
  CFAbsoluteTime at;
  CFLocaleRef loc;
  CFStringRef str;
  CFDateFormatterRef fmt;
  CFTimeZoneRef tz;
  
  loc = CFLocaleCreate (NULL, CFSTR("de_DE"));
  fmt = CFDateFormatterCreate (NULL, loc, kCFDateFormatterFullStyle,
    kCFDateFormatterShortStyle);
  tz = CFTimeZoneCreateWithTimeIntervalFromGMT (NULL, 3600.0);
  CFDateFormatterSetProperty (fmt, kCFDateFormatterTimeZone, tz);
  
  str = CFDateFormatterGetFormat (fmt);
  PASS_CFEQ(str, CFSTR("EEEE, d. MMMM y 'um' HH:mm"),
    "Default format for de_DE locale is EEEE, d. MMMM y 'um' HH:mm");
  
  str = CFDateFormatterCreateStringWithAbsoluteTime (NULL, fmt, 65.0);
  PASS_CFEQ(str, CFSTR("Montag, 1. Januar 2001 um 01:01"),
    "Absolute time can be formatted using full date style.");
  CFRelease(str);
  
  PASS_CF(CFDateFormatterGetAbsoluteTimeFromString (fmt,
       CFSTR("Montag, 1. Januar 2011 23:00"), NULL, &at),
       "Absolute time gotten for 2/1/2003");
  PASS_CF(at == 315612000.0,
    "Absolute time for Montag, 1. Januar 2011 23:00 is %f", at);
  
  CFRelease(fmt);
  
  fmt = CFDateFormatterCreate (NULL, loc, kCFDateFormatterNoStyle,
    kCFDateFormatterNoStyle);
  str = CFDateFormatterCreateStringWithAbsoluteTime (NULL, fmt, 65.0);
  testHopeful = true;
  PASS_CFEQ(str, CFSTR("20010101 02:01 AM"),
    "Absolute time can be formatted using no date style.");
  CFRelease(str);
  
  PASS_CF(CFDateFormatterGetAbsoluteTimeFromString (fmt,
                                                 CFSTR("20050403 02:01 vorm."),
                                                 NULL, &at),
    "Absolute time gotten for 20050403 02:01 vorm.");
  PASS_CF(at == 134186460.0,
    "Absolute time for 20050403 02:01 vorm. is %f", at);
  testHopeful = false;
  
  CFRelease(fmt);
  CFRelease(loc);
  
  return 0;
}