1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
//! Small utility helpers for encoding, JSON extraction, ranking, and time formatting.
//!
//! The functions in this module are intentionally lightweight and dependency-free
//! to keep hot paths fast and reduce compile times. They are used by networking,
//! indexing, and UI code.
use Value;
use Write;
/// What: Ensure mouse capture is enabled for the TUI.
///
/// Inputs:
/// - None.
///
/// Output:
/// - No return value; enables mouse capture on stdout if not in headless mode.
///
/// Details:
/// - Should be called after spawning external processes (like terminals) that might disable mouse capture.
/// - Safe to call multiple times.
/// - In headless/test mode (`PACSEA_TEST_HEADLESS=1`), this is a no-op to prevent mouse escape sequences from appearing in test output.
/// - If terminal raw mode is not active, this is a no-op to avoid leaking mouse-reporting sequences into normal shell sessions (e.g. tests/doctests).
/// - On Windows, this is a no-op as mouse capture is handled differently.
/// What: Percent-encode a string for use in URLs according to RFC 3986.
///
/// Inputs:
/// - `input`: String to encode.
///
/// Output:
/// - Returns a percent-encoded string where reserved characters are escaped.
///
/// Details:
/// - Unreserved characters as per RFC 3986 (`A-Z`, `a-z`, `0-9`, `-`, `.`, `_`, `~`) are left as-is.
/// - Space is encoded as `%20` (not `+`).
/// - All other bytes are encoded as two uppercase hexadecimal digits prefixed by `%`.
/// - Operates on raw bytes from the input string; any non-ASCII bytes are hex-escaped.
/// # Examples
/// ```
/// use pacsea::util::percent_encode;
///
/// // Encoding a package name for a URL, like in API calls to the AUR
/// assert_eq!(percent_encode("linux-zen"), "linux-zen");
///
/// // Encoding a search query with spaces for the package database
/// assert_eq!(percent_encode("terminal emulator"), "terminal%20emulator");
///
/// // Encoding a maintainer name with special characters
/// assert_eq!(percent_encode("John Doe <john@example.com>"), "John%20Doe%20%3Cjohn%40example.com%3E");
/// ```
/// What: Extract a string value from a JSON object by key, defaulting to empty string.
///
/// Inputs:
/// - `v`: JSON value to extract from.
/// - `key`: Key to look up in the JSON object.
///
/// Output:
/// - Returns the string value if found, or an empty string if the key is missing or not a string.
///
/// Details:
/// - Returns `""` if the key is missing or the value is not a string type.
/// # Examples
/// ```
/// use pacsea::util::s;
/// use serde_json::json;
///
/// // Simulating a real AUR RPC API response for a package like 'yay'
/// let aur_pkg_info = json!({
/// "Name": "yay",
/// "Version": "12.3.4-1",
/// "Description": "Yet another Yogurt - An AUR Helper written in Go"
/// });
/// assert_eq!(s(&aur_pkg_info, "Name"), "yay");
/// assert_eq!(s(&aur_pkg_info, "Description"), "Yet another Yogurt - An AUR Helper written in Go");
/// assert_eq!(s(&aur_pkg_info, "Maintainer"), ""); // Returns empty string for missing keys
///
/// // Simulating a package search result from the official repository API
/// let repo_pkg_info = json!({
/// "pkgname": "firefox",
/// "pkgver": "128.0-1",
/// "repo": "extra"
/// });
/// assert_eq!(s(&repo_pkg_info, "pkgname"), "firefox");
/// assert_eq!(s(&repo_pkg_info, "repo"), "extra");
/// ```
/// What: Extract the first available string from a list of candidate keys.
///
/// Inputs:
/// - `v`: JSON value to extract from.
/// - `keys`: Array of candidate keys to try in order.
///
/// Output:
/// - Returns `Some(String)` for the first key that maps to a JSON string, or `None` if none match.
///
/// Details:
/// - Tries keys in the order provided and returns the first match.
/// - Returns `None` if no key maps to a string value.
/// # Examples
/// ```
/// use pacsea::util::ss;
/// use serde_json::json;
///
/// // Trying multiple possible version keys from different AUR API responses
/// let pkg_info = json!({
/// "Version": "1.2.3",
/// "pkgver": "1.2.3",
/// "ver": "1.2.3"
/// });
/// // Returns the first matching key: "pkgver"
/// assert_eq!(ss(&pkg_info, &["pkgver", "Version", "ver"]), Some("1.2.3".to_string()));
///
/// // Trying to get a maintainer, falling back to a packager field
/// let maintainer_info = json!({
/// "Packager": "Arch Linux Pacsea Team <pacsea@example.org>"
/// // "Maintainer" key is missing to demonstrate fallback
/// });
/// assert_eq!(ss(&maintainer_info, &["Maintainer", "Packager"]), Some("Arch Linux Pacsea Team <pacsea@example.org>".to_string()));
///
/// // Returns None if no key matches
/// assert_eq!(ss(&pkg_info, &["License", "URL"]), None);
/// ```
/// What: Extract an array of strings from a JSON object by trying keys in order.
///
/// Inputs:
/// - `v`: JSON value to extract from.
/// - `keys`: Array of candidate keys to try in order.
///
/// Output:
/// - Returns the first found array as `Vec<String>`, filtering out non-string elements.
/// - Returns an empty vector if no array of strings is found.
///
/// Details:
/// - Tries keys in the order provided and returns the first array found.
/// - Filters out non-string elements from the array.
/// - Returns an empty vector if no key maps to an array or if all elements are non-string.
/// # Examples
/// ```
/// use pacsea::util::arrs;
/// use serde_json::json;
///
/// // Getting the list of dependencies from a package's metadata
/// let pkg_metadata = json!({
/// "Depends": ["glibc", "gcc-libs", "bash"],
/// "MakeDepends": ["git", "pkgconf"]
/// });
/// // Tries "Depends" first, returns those dependencies
/// assert_eq!(arrs(&pkg_metadata, &["Depends", "MakeDepends"]), vec!["glibc", "gcc-libs", "bash"]);
///
/// // Getting the list of provides or alternate package names
/// let provides_info = json!({
/// "Provides": ["python-cryptography", "python-crypto"],
/// "Conflicts": ["python-crypto-legacy"]
/// });
/// assert_eq!(arrs(&provides_info, &["Provides", "Replaces"]), vec!["python-cryptography", "python-crypto"]);
///
/// // Returns empty vector if no array of strings is found
/// let simple_json = json!({"Name": "firefox"});
/// assert_eq!(arrs(&simple_json, &["Depends", "OptDepends"]), Vec::<String>::new());
/// ```
/// What: Extract an unsigned 64-bit integer by trying multiple keys and representations.
///
/// Inputs:
/// - `v`: JSON value to extract from.
/// - `keys`: Array of candidate keys to try in order.
///
/// Output:
/// - Returns `Some(u64)` if a valid value is found, or `None` if no usable value is found.
///
/// Details:
/// - Accepts any of the following representations for the first matching key:
/// - JSON `u64`
/// - JSON `i64` convertible to `u64`
/// - String that parses as `u64`
/// - Tries keys in the order provided and returns the first match.
/// - Returns `None` if no key maps to a convertible value.
/// # Examples
/// ```
/// use pacsea::util::u64_of;
/// use serde_json::json;
///
/// // Extracting the vote count from an AUR package info (can be a number or a string)
/// let aur_vote_data = json!({
/// "NumVotes": 123,
/// "Popularity": "45.67"
/// });
/// assert_eq!(u64_of(&aur_vote_data, &["NumVotes", "Votes"]), Some(123));
///
/// // Extracting the first seen timestamp (often a string in JSON APIs)
/// let timestamp_data = json!({
/// "FirstSubmitted": "1672531200",
/// "LastModified": 1672617600
/// });
/// assert_eq!(u64_of(×tamp_data, &["FirstSubmitted", "Submitted"]), Some(1672531200));
/// assert_eq!(u64_of(×tamp_data, &["LastModified", "Modified"]), Some(1672617600));
///
/// // Returns None for negative numbers or if no convertible value is found
/// let negative_data = json!({"OutOfDate": -1});
/// assert_eq!(u64_of(&negative_data, &["OutOfDate"]), None);
/// ```
use crateSource;
/// Rank how well a package name matches a query using fuzzy matching (fzf-style) with a provided matcher.
///
/// Inputs:
/// - `name`: Package name to match against
/// - `query`: Query string to match
/// - `matcher`: Reference to a `SkimMatcherV2` instance to reuse across multiple calls
///
/// Output:
/// - `Some(score)` if the query matches the name (higher score = better match), `None` if no match
///
/// Details:
/// - Uses the provided `fuzzy_matcher::skim::SkimMatcherV2` for fzf-style fuzzy matching
/// - Returns scores where higher values indicate better matches
/// - Returns `None` when the query doesn't match at all
/// - This function is optimized for cases where the matcher can be reused across multiple calls
/// Rank how well a package name matches a query using fuzzy matching (fzf-style).
///
/// Inputs:
/// - `name`: Package name to match against
/// - `query`: Query string to match
///
/// Output:
/// - `Some(score)` if the query matches the name (higher score = better match), `None` if no match
///
/// Details:
/// - Uses `fuzzy_matcher::skim::SkimMatcherV2` for fzf-style fuzzy matching
/// - Returns scores where higher values indicate better matches
/// - Returns `None` when the query doesn't match at all
/// - For performance-critical code that calls this function multiple times with the same query,
/// consider using `fuzzy_match_rank_with_matcher` instead to reuse the matcher instance
/// # Examples
/// ```
/// use pacsea::util::fuzzy_match_rank;
///
/// // Fuzzy matching a package name during search (e.g., user types "rg" for "ripgrep")
/// let score = fuzzy_match_rank("ripgrep", "rg");
/// assert!(score.is_some()); // Should match and return a score
/// assert!(score.unwrap() > 0); // Higher score means better match
///
/// // Another common search: "fz" matching "fzf" (a command-line fuzzy finder)
/// let fzf_score = fuzzy_match_rank("fzf", "fz");
/// assert!(fzf_score.is_some());
///
/// // Exact match should have the highest score
/// let exact_score = fuzzy_match_rank("pacman", "pacman");
/// let partial_score = fuzzy_match_rank("pacman", "pac");
/// assert!(exact_score.unwrap() > partial_score.unwrap());
///
/// // No match returns None (e.g., searching "xyz" for "linux")
/// assert_eq!(fuzzy_match_rank("linux", "xyz"), None);
///
/// // Empty or whitespace-only query returns None
/// assert_eq!(fuzzy_match_rank("vim", ""), None);
/// assert_eq!(fuzzy_match_rank("neovim", " "), None);
/// ```
/// What: Determine ordering weight for a package source.
///
/// Inputs:
/// - `src`: Package source to rank.
///
/// Output:
/// - Returns a `u8` weight where lower values indicate higher priority.
///
/// Details:
/// - Used to sort results such that official repositories precede AUR, and core repos precede others.
/// - Order: `core` => 0, `extra` => 1, other official repos => 2, AUR => 3.
/// - Case-insensitive comparison for repository names.
/// What: Rank how well a package name matches a query (lower is better).
///
/// Inputs:
/// - `name`: Package name to match against.
/// - `query_lower`: Query string (must be lowercase).
///
/// Output:
/// - Returns a `u8` rank: 0 = exact match, 1 = prefix match, 2 = substring match, 3 = no match.
///
/// Details:
/// - Expects `query_lower` to be lowercase; the name is lowercased internally.
/// - Returns 3 (no match) if the query is empty.
/// What: Convert an optional Unix timestamp (seconds) to a UTC date-time string.
///
/// Inputs:
/// - `ts`: Optional Unix timestamp in seconds since epoch.
///
/// Output:
/// - Returns a formatted string `YYYY-MM-DD HH:MM:SS` (UTC), or empty string for `None`, or numeric string for negative timestamps.
///
/// Details:
/// - Returns an empty string for `None`.
/// - Negative timestamps are returned as their numeric string representation.
/// - Output format: `YYYY-MM-DD HH:MM:SS` (UTC).
/// - This implementation performs a simple conversion using loops and does not account for leap seconds.
/// # Examples
/// ```
/// use pacsea::util::ts_to_date;
///
/// // Converting the timestamp for the release of a significant Arch Linux package update
/// // Example: A major 'glibc' or 'linux' package release
/// assert_eq!(ts_to_date(Some(1680307200)), "2023-04-01 00:00:00");
///
/// // Converting the 'LastModified' timestamp from an AUR package's metadata
/// // This is commonly used to show when a package was last updated in the AUR
/// assert_eq!(ts_to_date(Some(1704067200)), "2024-01-01 00:00:00");
///
/// // Handling the case where no timestamp is available (e.g., a package with no build date)
/// assert_eq!(ts_to_date(None), "");
/// ```
/// Leap year predicate for the proleptic Gregorian calendar.
/// Return `true` if year `y` is a leap year.
///
/// Inputs:
/// - `y`: Year (Gregorian calendar)
///
/// Output:
/// - `true` when `y` is a leap year; `false` otherwise.
///
/// Notes:
/// - Follows Gregorian rule: divisible by 4 and not by 100, unless divisible by 400.
const
/// What: Open a file in the default editor (cross-platform).
///
/// Inputs:
/// - `path`: Path to the file to open.
///
/// Output:
/// - No return value; spawns a background process to open the file.
///
/// Details:
/// - On Windows, uses `PowerShell`'s `Invoke-Item` to open files with the default application, with fallback to `cmd start`.
/// - On Unix-like systems (Linux/macOS), uses `xdg-open` (Linux) or `open` (macOS).
/// - Spawns the command in a background thread and ignores errors.
/// # Examples
/// ```
/// use pacsea::util::open_file;
/// use std::path::Path;
///
/// // Opening a downloaded package's PKGBUILD for inspection
/// let pkgbuild_path = Path::new("/tmp/linux-zen/PKGBUILD");
/// open_file(pkgbuild_path); // Launches the default text editor
///
/// // Opening the local Pacsea configuration file for editing
/// let config_path = Path::new("/home/alice/.config/pacsea/settings.conf");
/// open_file(config_path); // Opens in the configured editor
///
/// // Note: This function runs asynchronously and does not block.
/// // It's safe to call even if the file doesn't exist (the OS will show an error).
/// ```
/// What: Open a URL in the default browser (cross-platform).
///
/// Inputs:
/// - `url`: URL string to open.
///
/// Output:
/// - No return value; spawns a background process to open the URL.
///
/// Details:
/// - On Windows, uses `cmd /c start`, with fallback to `PowerShell` `Start-Process`.
/// - On Unix-like systems (Linux/macOS), uses `xdg-open` (Linux) or `open` (macOS).
/// - Spawns the command in a background thread and ignores errors.
/// - During tests, this is a no-op to avoid opening real browser windows.
/// # Examples
/// ```
/// use pacsea::util::open_url;
///
/// // Opening the AUR page of a package for manual review
/// open_url("https://aur.archlinux.org/packages/linux-zen");
///
/// // Opening the Arch Linux package search in a browser
/// open_url("https://archlinux.org/packages/?q=neovim");
///
/// // Opening the Pacsea project's GitHub page for issue reporting
/// open_url("https://github.com/Firstp1ck/Pacsea");
///
/// // Note: This function runs asynchronously and does not block.
/// // During tests (`cargo test`), it's a no-op to prevent opening browsers.
/// ```
/// Build curl command arguments for fetching a URL.
///
/// On Windows, adds `-k` flag to skip SSL certificate verification to work around
/// common SSL certificate issues (exit code 77). On other platforms, uses standard
/// SSL verification.
///
/// Inputs:
/// - `url`: The URL to fetch
/// - `extra_args`: Additional curl arguments (e.g., `["--max-time", "10"]`)
///
/// Output:
/// - Vector of curl arguments ready to pass to `Command::args()`
///
/// Details:
/// - Base arguments: `-sSLf` (silent, show errors, follow redirects, fail on HTTP errors)
/// - Windows: Adds `-k` to skip SSL verification
/// - Adds `--max-filesize 10485760` to cap response bodies at 10 MiB
/// - Adds User-Agent header to avoid being blocked by APIs
/// - Appends `extra_args` and `url` at the end
/// # Examples
/// ```
/// use pacsea::util::curl_args;
///
/// // Building arguments to fetch package info from the AUR RPC API
/// let aur_args = curl_args("https://aur.archlinux.org/rpc/?v=5&type=info&arg=linux-zen", &["--max-time", "10"]);
/// // On Windows, includes -k flag; always includes -sSLf and User-Agent
/// assert!(aur_args.contains(&"-sSLf".to_string()));
/// assert!(aur_args.contains(&"-H".to_string()));
/// // User-Agent is browser-like (Firefox) with Pacsea identifier
/// let user_agent = aur_args.iter().find(|arg| arg.contains("Mozilla") && arg.contains("Pacsea/")).unwrap();
/// assert!(user_agent.contains("Mozilla/5.0"));
/// assert!(user_agent.contains("Firefox"));
/// assert!(user_agent.contains("Pacsea/"));
/// assert!(aur_args.contains(&"--max-time".to_string()));
/// assert!(aur_args.contains(&"10".to_string()));
/// assert!(aur_args.last().unwrap().starts_with("https://aur.archlinux.org"));
///
/// // Building arguments to fetch the core repository database
/// let repo_args = curl_args("https://archlinux.org/packages/core/x86_64/pacman/", &["--compressed"]);
/// assert!(repo_args.contains(&"--compressed".to_string()));
/// assert!(repo_args.last().unwrap().contains("archlinux.org"));
///
/// // Building arguments with no extra options
/// let simple_args = curl_args("https://example.com/feed", &[]);
/// assert_eq!(simple_args.last().unwrap(), "https://example.com/feed");
/// ```
/// What: Parse a single update entry line in the format "name - `old_version` -> name - `new_version`".
///
/// Inputs:
/// - `line`: A trimmed line from the updates file
///
/// Output:
/// - `Some((name, old_version, new_version))` if parsing succeeds, `None` otherwise
///
/// Details:
/// - Parses format: "name - `old_version` -> name - `new_version`"
/// - Returns `None` for empty lines or invalid formats
/// - Uses `rfind` to find the last occurrence of " - " to handle package names that may contain dashes
/// - Normalizes the right-hand side with the same ` -> ` rules as pacman parsing so a merged
/// `oldver -> newver` chain never becomes a single `new_version` string in column three
/// # Examples
/// ```
/// use pacsea::util::parse_update_entry;
///
/// // Parsing a standard package update line from `pacman -Spu` or similar output
/// let update_line = "linux - 6.10.1.arch1-1 -> linux - 6.10.2.arch1-1";
/// let parsed = parse_update_entry(update_line);
/// assert_eq!(parsed, Some(("linux".to_string(), "6.10.1.arch1-1".to_string(), "6.10.2.arch1-1".to_string())));
///
/// // Parsing an update for a package with a hyphen in its name (common in AUR)
/// let aur_update_line = "python-requests - 2.31.0-1 -> python-requests - 2.32.0-1";
/// let aur_parsed = parse_update_entry(aur_update_line);
/// assert_eq!(aur_parsed, Some(("python-requests".to_string(), "2.31.0-1".to_string(), "2.32.0-1".to_string())));
///
/// // Handling a malformed or empty line (returns None)
/// assert_eq!(parse_update_entry(""), None);
/// assert_eq!(parse_update_entry("invalid line"), None);
/// ```
/// What: Return today's UTC date formatted as `YYYYMMDD` using only the standard library.
///
/// Inputs:
/// - None (uses current system time).
///
/// Output:
/// - Returns a string in format `YYYYMMDD` representing today's date in UTC.
///
/// Details:
/// - Uses a simple conversion from Unix epoch seconds to a UTC calendar date.
/// - Matches the same leap-year logic as `ts_to_date`.
/// - Falls back to epoch date (1970-01-01) if system time is before 1970.