/* app.c */

#include "app.h"

#include <stdio.h>
#include <time.h>

/* macros ============================================================== */
/* constants =========================================================== */
/* types =============================================================== */
/* structures ========================================================== */
/* private data ======================================================== */
/* private functions =================================================== */
/* internal public data ================================================ */
/* internal public functions =========================================== */
/* entry points ======================================================== */

/* ---------------------------------------------------------------------
   --------------------------------------------------------------------- */
int date_cde (int argc, char const **argv, void *p_user)
{
   int ret = 0;

   if (argc == 1)
   {
      time_t now = time (NULL);
      struct tm tm = *localtime (&now);
      char s[64];
      char const *s_user = p_user ? p_user : "";

      strftime (s, sizeof s, "%A %d-%m-%Y (week %W)", &tm);
      printf ("[%s] today is %s\n", s_user, s);
   }
   else
   {
      printf ("date change ...\n");
   }

   return ret;
}

/* ---------------------------------------------------------------------
   --------------------------------------------------------------------- */
int time_cde (int argc, char const **argv, void *p_user)
{
   int ret = 0;

   if (argc == 1)
   {
      time_t now = time (NULL);
      struct tm tm = *localtime (&now);
      char s[16];
      char const *s_user = p_user ? p_user : "";

      strftime (s, sizeof s, "%H:%M:%S", &tm);
      printf (" %s\n", s);
      printf ("[%s] it's now %s\n", s_user, s);
   }
   else
   {
      printf ("time change ...\n");
   }


   return ret;
}

/* public data ========================================================= */

char const date_man[] =
{
   "[yyyy[ mm[ dd]]]\n"
};

char const time_man[] =
{
   "[hh[ mm[ ss]]]\n"
};
