logo

utils-std

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

date.sh (2484B)


  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=21
  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. #usage="\
  54. #date [-uR] [-d datetime] [+format]
  55. #date [-uR] -f now_format now [+format]
  56. #"
  57. # atf_check -s 'exit:1' -e "inline:date: Error: Unrecognised option: '-x'\n${usage}" ../cmd/date -x
  58. #atf_test_case devfull
  59. #devfull_body() {
  60. # has_glibc && atf_skip "glibc ignoring write errors for puts()"
  61. # [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for puts()"
  62. # [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for puts()"
  63. #
  64. # atf_check -s exit:1 -e 'inline:date: puts: No space left on device\n' sh -c '../cmd/date >/dev/full'
  65. #}
  66. #atf_test_case utc
  67. #utc_body() {
  68. # atf_check -o "match:^[0-9]+$" ../cmd/date -u '+%s'
  69. #}
  70. #atf_test_case timestamp
  71. #timestamp_body() {
  72. # atf_check -s 'exit:1' -e "inline:date: Error: Missing operand for option: '-d'\n${usage}" ../cmd/date -u -d
  73. #
  74. # # 36893488147419103232 = 2^65
  75. # atf_check -s 'exit:1' -e not-empty ../cmd/date -u -d @36893488147419103232
  76. #}