elodie icon indicating copy to clipboard operation
elodie copied to clipboard

strftime: timestamp 24hours %H is working as %I 12hours

Open L00PN00B opened this issue 1 year ago • 1 comments

Hi Jaisen,

I converted several image with the following ~/.elodie/config.ini

[Directory]
month=%m
year=%Y
full_path=%year/%album/%month/

[File]
date=%Y%m%d_%H%M%S
name=%date.%extension

As you can see, according to the CheatSheet https://strftime.org/ the name of the files should look like: 20241028_205600.jpg ___________^^ 20 in 24 hours format.

Unfortunately %H which is defined as,

"%H 07 Hour (24-hour clock) as a zero-padded decimal number."

creates a filename like that: 20241028_085600.jpg ___________^^ 08 in 12 hours format (which should be %I, not %H).

How can I fix this for several thousand files without importing (because of multiple source directories) them again?

best regards, LN

L00PN00B avatar Oct 28 '24 08:10 L00PN00B

I'm not able to reproduce this issue. Please link to a source file that exhibits this behavior.

python3 -c "
      #!/usr/bin/env python3
      import time
      from elodie.filesystem import FileSystem

      # Test various hours to demonstrate 24-hour format
      test_cases = [
          (0, '00'),   # Midnight - should be 00 (24h), not 12 (12h)
          (1, '01'),   # 1 AM
          (8, '08'),   # 8 AM
          (12, '12'),  # Noon - same in both formats
          (13, '13'),  # 1 PM - should be 13 (24h), not 01 (12h)
          (20, '20'),  # 8 PM - should be 20 (24h), not 08 (12h)
          (23, '23'),  # 11 PM - should be 23 (24h), not 11 (12h)
      ]

      # Create filesystem instance
      filesystem = FileSystem()

      print('Testing %H 24-hour format in Elodie:')
      print('=====================================')

      for hour, expected_hour_str in test_cases:
          # Create mock metadata with specific hour and all required fields
          metadata = {
              'date_taken': time.struct_time((2024, 10, 28, hour, 30, 0, 0, 302, 0)),
              'extension': 'jpg',
              'original_name': 'test',
              'title': None
          }

          # Get filename using default format which includes %H
          file_name = filesystem.get_file_name(metadata)

          # Extract just the hour portion from the filename
          # Default format is %Y-%m-%d_%H-%M-%S, so hour is at position 11-12
          actual_hour = file_name[11:13]

          status = '✓ PASS' if actual_hour == expected_hour_str else '✗ FAIL'
          format_type = '24-hour' if actual_hour == expected_hour_str else '12-hour'

          print(f'Hour {hour:2d} → {actual_hour} ({format_type}) {status} (filename: {file_name})')

      print('')
      print('All tests passing indicates %H is working correctly in 24-hour format.')
      ")
  ⎿  Testing %H 24-hour format in Elodie:                                  
     =====================================
     Hour  0 → 00 (24-hour) ✓ PASS (filename: 2024-10-28_00-30-00-test.jpg)
     Hour  1 → 01 (24-hour) ✓ PASS (filename: 2024-10-28_01-30-00-test.jpg)
     Hour  8 → 08 (24-hour) ✓ PASS (filename: 2024-10-28_08-30-00-test.jpg)
     Hour 12 → 12 (24-hour) ✓ PASS (filename: 2024-10-28_12-30-00-test.jpg)
     Hour 13 → 13 (24-hour) ✓ PASS (filename: 2024-10-28_13-30-00-test.jpg)
     Hour 20 → 20 (24-hour) ✓ PASS (filename: 2024-10-28_20-30-00-test.jpg)
     Hour 23 → 23 (24-hour) ✓ PASS (filename: 2024-10-28_23-30-00-test.jpg)

     All tests passing indicates %H is working correctly in 24-hour format.

jmathai avatar Oct 16 '25 03:10 jmathai