Bug 231705 - pom(6) incorrect output
Summary: pom(6) incorrect output
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-09-25 06:24 UTC by Andrew "RhodiumToad" Gierth
Modified: 2020-07-12 14:28 UTC (History)
1 user (show)

See Also:


Attachments
patch for pom(6) (1.11 KB, patch)
2018-09-25 06:24 UTC, Andrew "RhodiumToad" Gierth
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew "RhodiumToad" Gierth 2018-09-25 06:24:40 UTC
Created attachment 197476 [details]
patch for pom(6)

$ TZ=GMT-1; export TZ
$ for d in 2018.01.30 2018.01.31 2018.02.01 2018.02.02; do printf "%s: " "$d"; pom -d $d; done
2018.01.30: The Moon is Waxing Gibbous (97% of Full)
2018.01.31: The Moon is Waning Gibbous (100% of Full)
2018.02.01: The Moon is Full
2018.02.02: The Moon is Waning Gibbous (98% of Full)

Line 2 shows incorrect output of "Waning Gibbous" instead of "Waxing Gibbous", and 100% instead of the correct 99%. This is caused by the fact that "today" has had 0.5 added to it before comparing against "tomorrow", which has not.

In addition, rounding means that the displayed percentage is often higher than the true value: today+0.5 is being rounded, not truncated, to 0 decimals by %1.0f.

A separate bug causes the computed GMT time to be possibly off by one hour: the value of tm_isdst from the current time is being kept rather than being set back to -1 when requesting a specific date or time.

Patch attached.
Comment 1 Thomas Munro 2018-11-19 11:37:39 UTC
Agreed.  I will commit this.
Comment 2 commit-hook freebsd_committer freebsd_triage 2018-11-20 00:07:25 UTC
A commit references this bug:

Author: tmunro
Date: Tue Nov 20 00:06:53 UTC 2018
New revision: 340655
URL: https://svnweb.freebsd.org/changeset/base/340655

Log:
  pom: Fix fencepost bugs.

  Under some conditions pom would report "waning" and then "full", show
  higher percentages than it should, and get confused by DST.  Fix.

  Before:

    2018.01.30: The Moon is Waxing Gibbous (97% of Full)
    2018.01.31: The Moon is Waning Gibbous (100% of Full)
    2018.02.01: The Moon is Full
    2018.02.02: The Moon is Waning Gibbous (98% of Full)

  After:

    2018.01.30: The Moon is Waxing Gibbous (96% of Full)
    2018.01.31: The Moon is Waxing Gibbous (99% of Full)
    2018.02.01: The Moon is Full
    2018.02.02: The Moon is Waning Gibbous (97% of Full)

  PR:                    231705
  Submitted by:          Andrew Gierth
  Approved by:           allanjude (mentor)
  MFC after:             2 weeks
  Differential Revision: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231705

Changes:
  head/usr.bin/pom/pom.c
Comment 3 commit-hook freebsd_committer freebsd_triage 2020-07-12 10:07:24 UTC
A commit references this bug:

Author: tmunro
Date: Sun Jul 12 10:07:01 UTC 2020
New revision: 363126
URL: https://svnweb.freebsd.org/changeset/base/363126

Log:
  MFC r340655
    pom: Fix fencepost bugs.

  PR:		231705
  Submitted by:   Andrew Gierth <andrew@tao11.riddles.org.uk>
  Approved by:	allanjude (mentor)

Changes:
_U  stable/12/
  stable/12/usr.bin/pom/pom.c