Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libfdatetime_floatingtime_copy_to_utf8_string: Midnight on first day of month not working #2

Open
siliconforks opened this issue May 27, 2024 · 1 comment

Comments

@siliconforks
Copy link

Consider the following program:

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include <libfdatetime.h>

void test_date(double days) {
  union {
    double x;
    uint64_t i;
  } u;

  u.x = days;

  libfdatetime_floatingtime_t * floatingtime = NULL;
  if (libfdatetime_floatingtime_initialize(&floatingtime, NULL) != 1) {
    fprintf(stderr, "libfdatetime_floatingtime_initialize failed\n");
    exit(EXIT_FAILURE);
  }

  if (libfdatetime_floatingtime_copy_from_64bit(floatingtime, u.i, NULL) != 1) {
    fprintf(stderr, "libfdatetime_floatingtime_copy_from_64bit failed\n");
    exit(EXIT_FAILURE);
  }

  uint8_t date_time_string[32];
  if (libfdatetime_floatingtime_copy_to_utf8_string(floatingtime,
        date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME |
        LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, NULL) != 1) {
    fprintf(stderr, "libfdatetime_floatingtime_copy_to_utf8_string failed\n");
    exit(EXIT_FAILURE);
  }

  printf("%f %" PRIx64 " %s\n", u.x, u.i, date_time_string);

  libfdatetime_floatingtime_free(&floatingtime, NULL);
}

int main(void) {
  for (double d = 45400; d < 45430; ++d) {
    test_date(d);
  }
  return 0;
}

This generates the following output:

45400.000000 40e62b0000000000 Apr 18, 2024 00:00:00.000000000
45401.000000 40e62b2000000000 Apr 19, 2024 00:00:00.000000000
45402.000000 40e62b4000000000 Apr 20, 2024 00:00:00.000000000
45403.000000 40e62b6000000000 Apr 21, 2024 00:00:00.000000000
45404.000000 40e62b8000000000 Apr 22, 2024 00:00:00.000000000
45405.000000 40e62ba000000000 Apr 23, 2024 00:00:00.000000000
45406.000000 40e62bc000000000 Apr 24, 2024 00:00:00.000000000
45407.000000 40e62be000000000 Apr 25, 2024 00:00:00.000000000
45408.000000 40e62c0000000000 Apr 26, 2024 00:00:00.000000000
45409.000000 40e62c2000000000 Apr 27, 2024 00:00:00.000000000
45410.000000 40e62c4000000000 Apr 28, 2024 00:00:00.000000000
45411.000000 40e62c6000000000 Apr 29, 2024 00:00:00.000000000
45412.000000 40e62c8000000000 Apr 30, 2024 00:00:00.000000000
45413.000000 40e62ca000000000 (0x40e62ca000000000)
45414.000000 40e62cc000000000 May 02, 2024 00:00:00.000000000
45415.000000 40e62ce000000000 May 03, 2024 00:00:00.000000000
45416.000000 40e62d0000000000 May 04, 2024 00:00:00.000000000
45417.000000 40e62d2000000000 May 05, 2024 00:00:00.000000000
45418.000000 40e62d4000000000 May 06, 2024 00:00:00.000000000
45419.000000 40e62d6000000000 May 07, 2024 00:00:00.000000000
45420.000000 40e62d8000000000 May 08, 2024 00:00:00.000000000
45421.000000 40e62da000000000 May 09, 2024 00:00:00.000000000
45422.000000 40e62dc000000000 May 10, 2024 00:00:00.000000000
45423.000000 40e62de000000000 May 11, 2024 00:00:00.000000000
45424.000000 40e62e0000000000 May 12, 2024 00:00:00.000000000
45425.000000 40e62e2000000000 May 13, 2024 00:00:00.000000000
45426.000000 40e62e4000000000 May 14, 2024 00:00:00.000000000
45427.000000 40e62e6000000000 May 15, 2024 00:00:00.000000000
45428.000000 40e62e8000000000 May 16, 2024 00:00:00.000000000
45429.000000 40e62ea000000000 May 17, 2024 00:00:00.000000000

The first day of the month is not working.

@joachimmetz joachimmetz changed the title Midnight on first day of month not working libfdatetime_floatingtime_copy_to_utf8_string: Midnight on first day of month not working May 27, 2024
@joachimmetz
Copy link
Member

Thanks for flagging, I'll have a closer look when time permits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants