/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* ECellDate - Date item for e-table.
 * Copyright (C) 2001 Ximian, Inc.
 * Author: Chris Lahey <clahey@ximian.com>
 */

#include <config.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <gal/util/e-util.h>
#include <gal/widgets/e-unicode.h>
#include <gal/util/e-i18n.h>
#include "e-cell-date.h"

#define PARENT_TYPE e_cell_text_get_type ()

static ECellTextClass *parent_class;

static char *
ecd_get_text(ECellText *cell, ETableModel *model, int col, int row)
{
	time_t date = GPOINTER_TO_INT (e_table_model_value_at(model, col, row));
	time_t nowdate = time(NULL);
	time_t yesdate;
	struct tm then, now, yesterday;
	char buf[26];
	gboolean done = FALSE;

	if (date == 0) {
		return e_utf8_from_locale_string (_("?"));
	}

	localtime_r (&date, &then);
	localtime_r (&nowdate, &now);
	if (then.tm_mday == now.tm_mday &&
	    then.tm_mon == now.tm_mon &&
	    then.tm_year == now.tm_year) {
		strftime (buf, 26, _("Today %l:%M %p"), &then);
		done = TRUE;
	}
	if (!done) {
		yesdate = nowdate - 60 * 60 * 24;
		localtime_r (&yesdate, &yesterday);
		if (then.tm_mday == yesterday.tm_mday &&
		    then.tm_mon == yesterday.tm_mon &&
		    then.tm_year == yesterday.tm_year) {
			strftime (buf, 26, _("Yesterday %l:%M %p"), &then);
			done = TRUE;
		}
	}
	if (!done) {
		int i;
		for (i = 2; i < 7; i++) {
			yesdate = nowdate - 60 * 60 * 24 * i;
			localtime_r (&yesdate, &yesterday);
			if (then.tm_mday == yesterday.tm_mday &&
			    then.tm_mon == yesterday.tm_mon &&
			    then.tm_year == yesterday.tm_year) {
				strftime (buf, 26, _("%a %l:%M %p"), &then);
				done = TRUE;
				break;
			}
		}
	}
	if (!done) {
		if (then.tm_year == now.tm_year) {
			strftime (buf, 26, _("%b %d %l:%M %p"), &then);
		} else {
			strftime (buf, 26, _("%b %d %Y"), &then);
		}
	}
#if 0
#ifdef CTIME_R_THREE_ARGS
	ctime_r (&date, buf, 26);
#else
	ctime_r (&date, buf);
#endif
#endif
	
	return e_utf8_from_locale_string (buf);
}

static void
ecd_free_text(ECellText *cell, char *text)
{
	g_free(text);
}

static void
e_cell_date_class_init (GtkObjectClass *object_class)
{
	ECellTextClass *ectc = (ECellTextClass *) object_class;

	parent_class = gtk_type_class (PARENT_TYPE);

	ectc->get_text  = ecd_get_text;
	ectc->free_text = ecd_free_text;
}

static void
e_cell_date_init (GtkObject *object)
{
}

/**
 * e_cell_date_new:
 * @fontname: font to be used to render on the screen
 * @justify: Justification of the string in the cell.
 *
 * Creates a new ECell renderer that can be used to render dates that
 * that come from the model.  The value returned from the model is
 * interpreted as being a time_t.
 *
 * The ECellDate object support a large set of properties that can be
 * configured through the Gtk argument system and allows the user to have
 * a finer control of the way the string is displayed.  The arguments supported
 * allow the control of strikeout, bold, color and a date filter.
 *
 * The arguments "strikeout_column", "bold_column" and "color_column" set
 * and return an integer that points to a column in the model that controls
 * these settings.  So controlling the way things are rendered is achieved
 * by having special columns in the model that will be used to flag whether
 * the date should be rendered with strikeout, or bolded.   In the case of
 * the "color_column" argument, the column in the model is expected to have
 * a string that can be parsed by gdk_color_parse().
 * 
 * Returns: an ECell object that can be used to render dates.
 */
ECell *
e_cell_date_new (const char *fontname, GtkJustification justify)
{
	ECellDate *ecd = gtk_type_new (e_cell_date_get_type ());

	e_cell_text_construct(E_CELL_TEXT(ecd), fontname, justify);
      
	return (ECell *) ecd;
}

E_MAKE_TYPE(e_cell_date, "ECellDate", ECellDate, e_cell_date_class_init, e_cell_date_init, PARENT_TYPE);
yarn/devel/electron6/files/node-fetch-2.6.1</option>
<option value='dependabot/npm_and_yarn/devel/electron6/files/serve-10.1.2'>dependabot/npm_and_yarn/devel/electron6/files/serve-10.1.2</option>
<option value='gnome-3.22'>gnome-3.22</option>
<option value='gnome-3.24'>gnome-3.24</option>
<option value='gnome-3.26'>gnome-3.26</option>
<option value='gnome-3.28'>gnome-3.28</option>
<option value='gnome-3.32'>gnome-3.32</option>
<option value='gnome-3.36'>gnome-3.36</option>
<option value='gstreamer'>gstreamer</option>
<option value='gstreamer-1.16'>gstreamer-1.16</option>
<option value='gstreamer0.10-removal'>gstreamer0.10-removal</option>
<option value='main' selected='selected'>main</option>
<option value='master'>master</option>
<option value='mate-1.16'>mate-1.16</option>
<option value='mate-1.18'>mate-1.18</option>
<option value='mate-1.20'>mate-1.20</option>
<option value='mate-1.22'>mate-1.22</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>FreeBSD GNOME current development ports (https://github.com/freebsd/freebsd-ports-gnome)</td><td class='sub right'></td></tr></table>
<table class='tabs'><tr><td>
<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/about/'>about</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/'>summary</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/refs/?id=5ce57b76c10c008ebfb97d56255559ee7f5e9056'>refs</a><a class='active' href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/devel/p5-Config-Record'>log</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/tree/devel/p5-Config-Record?id=5ce57b76c10c008ebfb97d56255559ee7f5e9056'>tree</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/devel/p5-Config-Record?id=5ce57b76c10c008ebfb97d56255559ee7f5e9056'>commit</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/diff/devel/p5-Config-Record?id=5ce57b76c10c008ebfb97d56255559ee7f5e9056'>diff</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/stats/devel/p5-Config-Record'>stats</a></td><td class='form'><form class='right' method='get' action='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/devel/p5-Config-Record'>
<input type='hidden' name='id' value='5ce57b76c10c008ebfb97d56255559ee7f5e9056'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/?id=5ce57b76c10c008ebfb97d56255559ee7f5e9056'>root</a>/<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/devel?id=5ce57b76c10c008ebfb97d56255559ee7f5e9056'>devel</a>/<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/devel/p5-Config-Record?id=5ce57b76c10c008ebfb97d56255559ee7f5e9056'>p5-Config-Record</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th></th><th class='left'>Commit message (<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/log/devel/p5-Config-Record?id=5ce57b76c10c008ebfb97d56255559ee7f5e9056&amp;showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Age</th><th class='left'>Files</th><th class='left'>Lines</th></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/devel/p5-Config-Record?id=bfb4671f1e34debad048e6a987bc9f8f20716056'>support STAGEDIR.</a></td><td>vanilla</td><td><span title='2013-10-28 21:46:25 +0800'>2013-10-28</span></td><td>2</td><td><span class='deletions'>-3</span>/<span class='insertions'>+1</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/devel/p5-Config-Record?id=3ff0383d3a2fb21cdb1e80822419f4aac7fd522f'>Add NO_STAGE all over the place in preparation for the staging support (cat: ...</a></td><td>bapt</td><td><span title='2013-09-21 01:13:42 +0800'>2013-09-21</span></td><td>1</td><td><span class='deletions'>-0</span>/<span class='insertions'>+1</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/devel/p5-Config-Record?id=2d86d413f735f7ab13bae1033a1114997b4b2f2b'>- Add LICENSE</a></td><td>sunpoet</td><td><span title='2013-09-14 15:42:44 +0800'>2013-09-14</span></td><td>2</td><td><span class='deletions'>-4</span>/<span class='insertions'>+5</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/devel/p5-Config-Record?id=4539b36e07dc5d3a00796c31225b2da419544ef0'>- Convert to new perl framework</a></td><td>az</td><td><span title='2013-08-03 02:21:05 +0800'>2013-08-03</span></td><td>1</td><td><span class='deletions'>-1</span>/<span class='insertions'>+2</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/devel/p5-Config-Record?id=23d30472414fca7c1181b6e926a83ceee454a130'>- Reassign to the heap at maintainer's request</a></td><td>tabthorpe</td><td><span title='2012-10-16 00:21:11 +0800'>2012-10-16</span></td><td>1</td><td><span class='deletions'>-6</span>/<span class='insertions'>+2</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/devel/p5-Config-Record?id=a7627ea1c0ac00b831f80a35d6b0e1f69f6ee9da'>The vast majority of pkg-descr files had the following format when they</a></td><td>dougb</td><td><span title='2011-10-24 17:11:38 +0800'>2011-10-24</span></td><td>1</td><td><span class='deletions'>-1</span>/<span class='insertions'>+1</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/devel/p5-Config-Record?id=6e2161b9981dadbb447039d09ec686f091ad3505'>- Make Test::Pod and friends optional</a></td><td>swills</td><td><span title='2011-10-16 06:13:32 +0800'>2011-10-16</span></td><td>1</td><td><span class='deletions'>-2</span>/<span class='insertions'>+2</span></td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports-gnome/commit/devel/p5-Config-Record?id=4428229e8770bd5f712eb4660005504197317366'>-remove MD5</a></td><td>ohauer</td><td><span title='2011-07-03 22:59:23 +0800'>2011-07-03</span></td><td>1</td><td><span class='deletions'>-1</span>/<span class='insertions'>+0</span></td></tr>