logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

date.sh (2997B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. target="$(dirname "$0")/../cmd/date"
  5. plans=27
  6. . "$(dirname "$0")/tap.sh"
  7. . "$(dirname "$0")/init_env.sh"
  8. export TZ=UTC
  9. export LC_ALL=C
  10. t 'epoch' '-u -d @1155544496 +%s' '1155544496
  11. '
  12. t 'rfc3339' '-u -d @1155544496 +%FT%T%z' '2006-08-14T08:34:56+0000
  13. '
  14. t 'rfc5322' '-u -d @1155544496 -R' 'Mon, 14 Aug 2006 08:34:56 +0000
  15. '
  16. t 'empty' '+' '
  17. '
  18. t 'echolike' '+hello_world' 'hello_world
  19. '
  20. t '@0' '-u -d @0 +%FT%T' '1970-01-01T00:00:00
  21. '
  22. t '@69' '-u -d @69 +%FT%T' '1970-01-01T00:01:09
  23. '
  24. t '@-69' '-u -d @-69 +%FT%T' '1969-12-31T23:58:51
  25. '
  26. t '1970-01-01T00:00:00Z' '-u -d 1970-01-01T00:00:00Z +%s' '0
  27. '
  28. t '1970-01-01T00:01:09Z' '-u -d 1970-01-01T00:01:09Z +%s' '69
  29. '
  30. t '1969-12-31T23:58:51Z' '-u -d 1969-12-31T23:58:51Z +%s' '-69
  31. '
  32. t '1969-12-31T23:58:51.00Z' '-u -d 1969-12-31T23:58:51.00Z +%s' '-69
  33. '
  34. t '1969-12-31T23:58:51,00Z' '-u -d 1969-12-31T23:58:51,00Z +%s' '-69
  35. '
  36. t 'f_option' '-u -j -f %Y-%m-%dT%H:%M:%S 2006-08-14T08:34:56 +%s' '1155544496
  37. '
  38. # Note the lack of setting seconds
  39. t 'mmddHHMM' '-j 07250554 +%Y-%m-%dT%H:%M' "$(date +%Y-07-25T05:54)
  40. "
  41. t 'mmddHHMM24' '-j 0725055424 +%Y-%m-%dT%H:%M' '2024-07-25T05:54
  42. '
  43. t 'mmddHHMM69' '-j 0628012069 +%Y-%m-%dT%H:%M' '1969-06-28T01:20
  44. '
  45. t 'mmddHHMMCCyy' '-j 072505542024 +%Y-%m-%dT%H:%M' '2024-07-25T05:54
  46. '
  47. t 'r_0' '-u -r 0 +%FT%T' '1970-01-01T00:00:00
  48. '
  49. t 'r_69' '-u -r 69 +%FT%T' '1970-01-01T00:01:09
  50. '
  51. t 'r_-69' '-u -r -69 +%FT%T' '1969-12-31T23:58:51
  52. '
  53. t 'iso Date' '-u -d 2025-02-10T21:05:53,437742835+01:00 -Idate' '2025-02-10
  54. '
  55. t 'iso Hours' '-u -d 2025-02-10T21:05:53,437742835+01:00 -Ihours' '2025-02-10T20+00:00
  56. '
  57. t 'iso Minutes' '-u -d 2025-02-10T21:05:53,437742835+01:00 -Iminutes' '2025-02-10T20:05+00:00
  58. '
  59. t 'iso Seconds' '-u -d 2025-02-10T21:05:53,437742835+01:00 -Iseconds' '2025-02-10T20:05:53+00:00
  60. '
  61. t 'iso Nano-Seconds' '-u -d 2025-02-10T21:05:53,437742835+01:00 -Ins' '2025-02-10T20:05:53,437742835+00:00
  62. '
  63. t '+foo%%bar' '+foo%%bar' 'foo%bar
  64. '
  65. #usage="\
  66. #date [-uR] [-d datetime] [+format]
  67. #date [-uR] -f now_format now [+format]
  68. #"
  69. # atf_check -s 'exit:1' -e "inline:date: Error: Unrecognised option: '-x'\n${usage}" ../cmd/date -x
  70. #atf_test_case devfull
  71. #devfull_body() {
  72. # has_glibc && atf_skip "glibc ignoring write errors for puts()"
  73. # [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for puts()"
  74. # [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for puts()"
  75. #
  76. # atf_check -s exit:1 -e 'inline:date: puts: No space left on device\n' sh -c '../cmd/date >/dev/full'
  77. #}
  78. #atf_test_case utc
  79. #utc_body() {
  80. # atf_check -o "match:^[0-9]+$" ../cmd/date -u '+%s'
  81. #}
  82. #atf_test_case timestamp
  83. #timestamp_body() {
  84. # atf_check -s 'exit:1' -e "inline:date: Error: Missing operand for option: '-d'\n${usage}" ../cmd/date -u -d
  85. #
  86. # # 36893488147419103232 = 2^65
  87. # atf_check -s 'exit:1' -e not-empty ../cmd/date -u -d @36893488147419103232
  88. #}