[Toybox] [PATCH] date.test: add some tests.

Rich Felker dalias at libc.org
Sat Oct 6 13:46:18 PDT 2018


On Sat, Oct 06, 2018 at 01:20:06PM -0500, Rob Landley wrote:
> On 10/05/2018 05:18 PM, enh wrote:
> > These are reasonable examples I found in AOSP.
> > +
> > +# Test embedded TZ to take a date in one time zone and display it in another.
> > +testing "TZ=" "TZ='America/Los_Angeles' date -d 'TZ=\"Europe/London\"
> > 2018-10-04 08:00'" "Thu Oct  4 00:00:00 PDT 2018\n" "" ""
> > +testing "TZ= @" "TZ='America/Los_Angeles' date -d 'TZ=\"GMT\"
> > @1533427200'" "Sat Aug  4 17:00:00 PDT 2018\n" "" ""
> 
> Hmmm, slight concern that I'm not sure how many timezones we should expect to be
> installed in a test environment.

You can use POSIX TZ strings rather than zoneinfo files for testing if
you don't know what will be installed. The format is:

	stdoffset[dst[offset][,start[/time],end[/time]]]

with offsets in the format:

	hh[:mm[:ss]]

start and end in the format:

	Jn - one-based julian day number not counting leap days
	n - zero-based julian day number counting leap days
	Mm,n,d - the d'th day (0=Synday) of week n (1-5) of month m (1-12)

Optional /time specifies the hour of the dst change.

For example, current US/Eastern is:

	TZ=EST5EDT,M3.2.0/2,M11.1.0/2

Full detail is here:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03

> I'm back poking at mkroot and trying to turn it into a test environment that can
> run the full toybox test suite under qemu, so I can finally have some proper
> tests for mount and insmod and such. It's a musl-based environment, and I dunno
> what musl does about timezones? (Glibc needs horrible generation and files and
> such, and uClibc _copied_glibc's_data_at_install_time_ off the build system,
> which was just crazy from a licensing perspective.)
> 
> Hey Rich: musl timezones? Do I have to do anything special, or what?

Most implementations including glibc and musl (not sure about Bionic)
use the standard zoneinfo format and data from:

	https://www.iana.org/time-zones

and, if you don't want to have them installed in the standard system
locations ([/usr]/share/zoneinfo; musl also searches /etc/zoneinfo)
they also support setting TZ to an absolute zoneinfo file pathname as
long as the program was not invoked suid/sgid/setcap.

Rich



More information about the Toybox mailing list