cleanup: move monthname to time.c

Weirdly, this function was declared in dive.h and defined in
subsurface-startup.c. Let's move declaration and definition to
more appropriate places, viz. subsurface-time.h and time.c.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-12-08 13:32:46 +01:00 committed by Dirk Hohndel
parent bbbd4c8818
commit 4c85357dcc
4 changed files with 13 additions and 12 deletions

View file

@ -204,8 +204,6 @@ extern void invalidate_dive_cache(struct dive *dc);
extern void set_autogroup(bool value);
extern int total_weight(const struct dive *);
const char *monthname(int mon);
extern const char *existing_filename;
extern bool has_planned(const struct dive *dive, bool planned);

View file

@ -18,6 +18,8 @@ extern int utc_weekday(timestamp_t timestamp);
extern timestamp_t parse_datetime(const char *s); /* returns 0 on error */
extern char *format_datetime(timestamp_t timestamp); /* ownership of string passed to caller */
extern const char *monthname(int mon);
#ifdef __cplusplus
}
#endif

View file

@ -115,16 +115,6 @@ const struct units *get_units()
return &prefs.units;
}
/* random helper functions, used here or elsewhere */
const char *monthname(int mon)
{
static const char month_array[12][4] = {
QT_TRANSLATE_NOOP("gettextFromC", "Jan"), QT_TRANSLATE_NOOP("gettextFromC", "Feb"), QT_TRANSLATE_NOOP("gettextFromC", "Mar"), QT_TRANSLATE_NOOP("gettextFromC", "Apr"), QT_TRANSLATE_NOOP("gettextFromC", "May"), QT_TRANSLATE_NOOP("gettextFromC", "Jun"),
QT_TRANSLATE_NOOP("gettextFromC", "Jul"), QT_TRANSLATE_NOOP("gettextFromC", "Aug"), QT_TRANSLATE_NOOP("gettextFromC", "Sep"), QT_TRANSLATE_NOOP("gettextFromC", "Oct"), QT_TRANSLATE_NOOP("gettextFromC", "Nov"), QT_TRANSLATE_NOOP("gettextFromC", "Dec"),
};
return translate("gettextFromC", month_array[mon]);
}
/*
* track whether we switched to importing dives
*/

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include "subsurface-time.h"
#include "subsurface-string.h"
#include "gettext.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@ -213,3 +214,13 @@ extern char *format_datetime(timestamp_t timestamp)
return strdup(buf);
}
/* Turn month (0-12) into three-character short name */
const char *monthname(int mon)
{
static const char month_array[12][4] = {
QT_TRANSLATE_NOOP("gettextFromC", "Jan"), QT_TRANSLATE_NOOP("gettextFromC", "Feb"), QT_TRANSLATE_NOOP("gettextFromC", "Mar"), QT_TRANSLATE_NOOP("gettextFromC", "Apr"), QT_TRANSLATE_NOOP("gettextFromC", "May"), QT_TRANSLATE_NOOP("gettextFromC", "Jun"),
QT_TRANSLATE_NOOP("gettextFromC", "Jul"), QT_TRANSLATE_NOOP("gettextFromC", "Aug"), QT_TRANSLATE_NOOP("gettextFromC", "Sep"), QT_TRANSLATE_NOOP("gettextFromC", "Oct"), QT_TRANSLATE_NOOP("gettextFromC", "Nov"), QT_TRANSLATE_NOOP("gettextFromC", "Dec"),
};
return translate("gettextFromC", month_array[mon]);
}