Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
date_format.c File Reference

Implements OP_DATE_FORMAT to format an epoch milliseconds timestamp using strftime. More...

#include <stdlib.h>
#include <string.h>
#include <time.h>
Include dependency graph for date_format.c:

Go to the source code of this file.

Functions

 if (ms.type !=VAL_INT||fmt.type !=VAL_STRING)
 if (!ptm)
 if (n==0)
 free (buf)
 free_value (ms)
 free_value (fmt)
 push_value (vm, out)

Variables

case OP_DATE_FORMAT
Value ms = pop_value(vm)
time_t secs = (time_t)(ms.i / 1000)
struct tm tmv = *ptm
struct tm * ptm = localtime(&secs)
size_t cap = 128
char * buf = (char *)malloc(cap)
size_t n = strftime(buf, cap, fmt.s, &tmv)
Value out
 else
 break

Detailed Description

Implements OP_DATE_FORMAT to format an epoch milliseconds timestamp using strftime.

Behavior:

  • Pops fmt string, then milliseconds since Unix epoch (int).
  • Formats the local time according to fmt and pushes a string.

Errors:

  • If types are wrong, prints error and pushes empty string to keep stack safe.

Definition in file date_format.c.

Function Documentation

◆ free()

free(buf)

◆ free_value() [1/2]

free_value(fmt)

◆ free_value() [2/2]

free_value(ms)
Here is the caller graph for this function:

◆ if() [1/3]

if(!ptm)

Definition at line 42 of file date_format.c.

Here is the call graph for this function:

◆ if() [2/3]

if(ms.type ! = VAL_INT || fmt.type != VAL_STRING)

Definition at line 29 of file date_format.c.

Here is the call graph for this function:

◆ if() [3/3]

if(n = = 0)

Definition at line 54 of file date_format.c.

◆ push_value()

push_value(vm,
out )
Here is the caller graph for this function:

Variable Documentation

◆ break

break

Definition at line 70 of file date_format.c.

◆ buf

char* buf = (char *)malloc(cap)

Definition at line 52 of file date_format.c.

◆ cap

size_t cap = 128

Definition at line 51 of file date_format.c.

◆ else

else
Initial value:
{
Value out
Definition apop.c:38
char * buf
Definition input_line.c:103
Value make_string(const char *s)
Construct a string Value by duplicating the given C string.
Definition value.c:95

Definition at line 63 of file date_format.c.

◆ ms

Value ms = pop_value(vm)

Definition at line 28 of file date_format.c.

◆ n

size_t n = strftime(buf, cap, fmt.s, &tmv)

Definition at line 53 of file date_format.c.

◆ OP_DATE_FORMAT

case OP_DATE_FORMAT

Definition at line 26 of file date_format.c.

◆ out

Value out

Definition at line 60 of file date_format.c.

◆ ptm

struct tm* ptm = localtime(&secs)

Definition at line 41 of file date_format.c.

◆ secs

time_t secs = (time_t)(ms.i / 1000)

Definition at line 36 of file date_format.c.

◆ tmv

tmv = *ptm

Definition at line 37 of file date_format.c.