#include "Config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "DateFormatter.h"
Go to the source code of this file.
◆ _Class
◆ _DateFormatter()
Class * _DateFormatter |
( |
void |
| ) |
|
Definition at line 132 of file DateFormatter.c.
132 {
135
138 .name = "DateFormatter",
142 .interfaceSize = sizeof(DateFormatterInterface),
144 });
145 });
146
147 return clazz;
148}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
#define do_once(once, block)
Executes the given block at most one time.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
Class * _Object(void)
The Object archetype.
◆ dateFromCharacters()
Definition at line 40 of file DateFormatter.c.
40 {
41
42#if defined(_WIN32)
43 fprintf(stderr, "WARNING: %s: not implemented (Windows)\n", __func__);
44#else
45 if (chars) {
46 struct tm time;
47
48 const char *res = strptime(chars, self->
fmt, &time);
49 if (res) {
50 const Time t = { .tv_sec = mktime(&time) };
52 }
53 }
54#endif
55
56 return NULL;
57}
#define alloc(type)
Allocate and initialize and instance of type.
struct timeval Time
Time (seconds and microseconds).
Microsecond-precision immutable dates.
Date * initWithTime(Date *self, const Time *time)
◆ dateFromString()
Definition at line 63 of file DateFormatter.c.
63 {
64
65 if (string) {
67 }
68
69 return NULL;
70}
MutableString * string(void)
Returns a new MutableString.
char * chars
The backing null-terminated UTF-8 encoded character array.
◆ initialize()
static void initialize |
( |
Class * |
clazz | ) |
|
|
static |
- See also
- Class::initialize(Class *)
Definition at line 118 of file DateFormatter.c.
118 {
119
124
125 tzset();
126}
ident interface
The interface of the Class.
◆ initWithFormat()
Definition at line 76 of file DateFormatter.c.
76 {
77
79 if (self) {
81 }
82
83 return self;
84}
#define super(type, obj, method,...)
Condition * init(Condition *self)
Initializes this Condition.
Object is the root Class of The Objectively Class hierarchy.
◆ stringFromDate()
Definition at line 90 of file DateFormatter.c.
90 {
91
92 const time_t seconds =
date->
time.tv_sec;
93 struct tm time;
94
95#if defined(_WIN32)
96 int err = localtime_s(&time, &seconds);
97 assert(err == 0);
98#else
99 ident res = localtime_r(&seconds, &time);
100 assert(res == &time);
101#endif
102
103 char *
str = calloc(1024,
sizeof(
char));
105
106 const size_t length = strftime(
str, 1024, self->
fmt, &time);
107 str = realloc(
str, length + 1 *
sizeof(
char));
109
111}
void * ident
The identity type, similar to Objective-C id.
Data * initWithMemory(Data *self, ident mem, size_t length)
Initializes this Data, taking ownership of the specified memory.
Date * date(void)
Returns a new Date with the current Time.
OBJECTIVELY_EXPORT String * str(const char *fmt,...)
A convenience function for instantiating Strings.