[Toybox] [PATCH] date: more test cleanup.

Rob Landley rob at landley.net
Thu Feb 14 06:07:23 PST 2019


On 2/14/19 6:53 AM, Rob Landley wrote:
> Ok, US/Arizona timezone, no daylight savings time... and the racy %a fetch is
> fetching _today's_ weekday and not the one for June 2. And nontrivial uses of it
> are basically just comparing the date output against _itself_ which may not
> prove anything...

Dumb little script to print out the day of the year:

#!/bin/bash

# Arguments YEAR-1900 MM DD
dayo()
{
  M="X144025036146"
  DAY="FriSatSunMonTueWedThu"
  X=$(($1+($1/4)+${M:$2:1}+$3))
  # Leap year
  [ $2 -gt 2 ] && [ $(($Y%4)) -eq 0 ] &&
    [ $(($Y%400)) -eq 0 -o $(($Y%100)) -ne 0 ] && $X=$(($X-1))
  echo ${DAY:$((3*(X%7))):3}
}

dayo $1 $2 $3

Unfortunately, when I tried to systematically test it, I went "there's a day of
the year field, I'll just feed that and a year into date and have it spit out of
the month and day...

  $ ./date -D %j -d 1
  Sun Jan  0 00:00:00 CST 1900

Does not do what I want. Of course neither does:

  $ busybox date -D %j -d 1
  Thu Feb 14 00:00:00 CST 2019

Alas, localtime considers weekday and day of the year to be generated fields,
with year/month/day what they're generated _from_...

Rob


More information about the Toybox mailing list