NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
node_conddate.c File Reference

Expando Node for a Conditional Date. More...

#include "config.h"
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "mutt/lib.h"
#include "node_conddate.h"
#include "helpers.h"
#include "node.h"
#include "parse.h"
#include "render.h"
+ Include dependency graph for node_conddate.c:

Go to the source code of this file.

Functions

struct NodeCondDatePrivatenode_conddate_private_new (int count, char period)
 Create new CondDate private data.
 
void node_conddate_private_free (void **ptr)
 Free CondDate private data - Implements ExpandoNode::ndata_free()
 
time_t cutoff_number (char period, int count)
 Calculate the cutoff time for n units.
 
time_t cutoff_this (char period)
 Calculcate the cutoff time of this unit.
 
int node_conddate_render (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render a CondDate Node - Implements ExpandoNode::render() -.
 
struct ExpandoNodenode_conddate_new (int count, char period, int did, int uid)
 Create a new CondDate ExpandoNode.
 
struct ExpandoNodenode_conddate_parse (const char *str, int did, int uid, const char **parsed_until, struct ExpandoParseError *err)
 Parse a CondDate format string - Implements ExpandoDefinition::parse() -.
 

Detailed Description

Expando Node for a Conditional Date.

Authors
  • Tóth János
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file node_conddate.c.

Function Documentation

◆ node_conddate_private_new()

struct NodeCondDatePrivate * node_conddate_private_new ( int  count,
char  period 
)

Create new CondDate private data.

Parameters
countNumber of 'units' to count
periodUnits, e.g. 'd' Day or 'm' Month
Return values
ptrNew CondDate private data

Definition at line 49 of file node_conddate.c.

50{
51 struct NodeCondDatePrivate *priv = mutt_mem_calloc(1, sizeof(struct NodeCondDatePrivate));
52
53 priv->count = count;
54 priv->period = period;
55
56 return priv;
57}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
Private data for a Conditional Date -.
Definition: node_conddate.h:33
int count
Number of 'units' to count.
Definition: node_conddate.h:34
char period
Units, e.g. 'd' Day or 'm' Month.
Definition: node_conddate.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_conddate_private_free()

void node_conddate_private_free ( void **  ptr)

Free CondDate private data - Implements ExpandoNode::ndata_free()

Parameters
ptrData to free

Definition at line 63 of file node_conddate.c.

64{
65 if (!ptr || !*ptr)
66 return;
67
68 FREE(ptr);
69}
#define FREE(x)
Definition: memory.h:45
+ Here is the caller graph for this function:

◆ cutoff_number()

time_t cutoff_number ( char  period,
int  count 
)

Calculate the cutoff time for n units.

Parameters
periodTime period, from [ymwdHM]
countNumber of time periods
Return values
numCutoff time

Calculate the cutoff time for, say, 3 months, or 2 hours.

Definition at line 79 of file node_conddate.c.

80{
81 time_t t = mutt_date_now();
82 struct tm tm = { 0 };
83 localtime_r(&t, &tm);
84
85 switch (period)
86 {
87 case 'y':
88 tm.tm_year -= count;
89 break;
90
91 case 'm':
92 tm.tm_mon -= count;
93 break;
94
95 case 'w':
96 tm.tm_mday -= (7 * count);
97 break;
98
99 case 'd':
100 tm.tm_mday -= count;
101 break;
102
103 case 'H':
104 tm.tm_hour -= count;
105 break;
106
107 case 'M':
108 tm.tm_min -= count;
109 break;
110 }
111
112 return mktime(&tm);
113}
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:456
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cutoff_this()

time_t cutoff_this ( char  period)

Calculcate the cutoff time of this unit.

Parameters
periodTime period, from [ymwdHM]
Return values
numCutoff time

Calculate the cutoff time of, say, this day (today), this month.

Definition at line 122 of file node_conddate.c.

123{
124 time_t t = mutt_date_now();
125 struct tm tm = { 0 };
126 localtime_r(&t, &tm);
127
128 switch (period)
129 {
130 case 'y':
131 tm.tm_mon = 0; // January
133
134 case 'm':
135 tm.tm_mday = 1; // 1st of the month
137
138 case 'd':
139 tm.tm_hour = 0; // Beginning of day (Midnight)
141
142 case 'H':
143 tm.tm_min = 0; // Beginning of hour
145
146 case 'M':
147 tm.tm_sec = 0; // Beginning of minute
148 break;
149
150 case 'w':
151 tm.tm_mday = 1;
152 break;
153 }
154
155 return mktime(&tm);
156}
#define FALLTHROUGH
Definition: lib.h:111
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_conddate_new()

struct ExpandoNode * node_conddate_new ( int  count,
char  period,
int  did,
int  uid 
)

Create a new CondDate ExpandoNode.

Parameters
countNumber of 'units' to count
periodUnits, e.g. 'd' Day or 'm' Month
didDomain ID
uidUnique ID
Return values
ptrNew CondDate ExpandoNode

Definition at line 191 of file node_conddate.c.

192{
193 struct ExpandoNode *node = node_new();
194 node->type = ENT_CONDDATE;
195 node->did = did;
196 node->uid = uid;
198
199 node->ndata = node_conddate_private_new(count, period);
201
202 return node;
203}
int node_conddate_render(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render a CondDate Node - Implements ExpandoNode::render() -.
struct ExpandoNode * node_new(void)
Create a new empty ExpandoNode.
Definition: node.c:39
@ ENT_CONDDATE
True/False date condition.
Definition: node.h:43
struct NodeCondDatePrivate * node_conddate_private_new(int count, char period)
Create new CondDate private data.
Definition: node_conddate.c:49
void node_conddate_private_free(void **ptr)
Free CondDate private data - Implements ExpandoNode::ndata_free()
Definition: node_conddate.c:63
Basic Expando Node.
Definition: node.h:67
int uid
Unique ID, e.g. ED_EMA_SIZE.
Definition: node.h:70
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:91
void * ndata
Private node data.
Definition: node.h:77
int did
Domain ID, e.g. ED_EMAIL.
Definition: node.h:69
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:68
void(* ndata_free)(void **ptr)
Function to free the private node data.
Definition: node.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function: