Fix description of Unix time, mention new function.

* lisp/calc/calc-forms.el (calcFunc-unixtime): Fix adjustment for
Unix time.
* doc/misc/calc.texi (Date Forms): Fix description of Unix time.
(Basic Operations on Units): Mention `calc-convert-exact-units'.
This commit is contained in:
Jay Belanger 2015-04-09 19:03:19 -05:00
parent c1daad42c6
commit e368697ce3
2 changed files with 16 additions and 22 deletions

View file

@ -11098,12 +11098,12 @@ noon GMT@.) Julian day numbering is largely used in astronomy.
@cindex Unix time format @cindex Unix time format
The Unix operating system measures time as an integer number of The Unix operating system measures time as an integer number of
seconds since midnight, Jan 1, 1970. To convert a Calc date seconds since midnight, Jan 1, 1970. To convert a Calc date
value into a Unix time stamp, first subtract 719164 (the code value into a Unix time stamp, first subtract 719163 (the code
for @samp{<Jan 1, 1970>}), then multiply by 86400 (the number of for @samp{<Jan 1, 1970>}), then multiply by 86400 (the number of
seconds in a day) and press @kbd{R} to round to the nearest seconds in a day) and press @kbd{R} to round to the nearest
integer. If you have a date form, you can simply subtract the integer. If you have a date form, you can simply subtract the
day @samp{<Jan 1, 1970>} instead of unpacking and subtracting day @samp{<Jan 1, 1970>} instead of unpacking and subtracting
719164. Likewise, divide by 86400 and add @samp{<Jan 1, 1970>} 719163. Likewise, divide by 86400 and add @samp{<Jan 1, 1970>}
to convert from Unix time to a Calc date form. (Note that to convert from Unix time to a Calc date form. (Note that
Unix normally maintains the time in the GMT time zone; you may Unix normally maintains the time in the GMT time zone; you may
need to subtract five hours to get New York time, or eight hours need to subtract five hours to get New York time, or eight hours
@ -27860,14 +27860,20 @@ while typing @kbd{u c au/yr @key{RET}} produces
If the units you request are inconsistent with the original units, the If the units you request are inconsistent with the original units, the
number will be converted into your units times whatever ``remainder'' number will be converted into your units times whatever ``remainder''
units are left over. (This can be disabled; @pxref{Customizing Calc}.) units are left over. For example, converting @samp{55 mph} into acres
For example, converting @samp{55 mph} into acres produces @samp{6.08e-3 acre / (m s)}. Remainder units are expressed in terms of
produces @samp{6.08e-3 acre / m s}. (Recall that multiplication binds
more strongly than division in Calc formulas, so the units here are
acres per meter-second.) Remainder units are expressed in terms of
``fundamental'' units like @samp{m} and @samp{s}, regardless of the ``fundamental'' units like @samp{m} and @samp{s}, regardless of the
input units. input units.
@kindex u n
@pindex calc-convert-exact-units
If you intend that your new units be consistent with the original
units, the @kbd{u n} (@code{calc-convert-exact-units}) command will
check the units before the conversion. For example, to change
@samp{mi/hr} to @samp{km/hr}, you could type @kbd{u c km @key{RET}},
but @kbd{u n km @key{RET}} would signal an error.
You would need to type @kbd{u n km/hr @key{RET}}.
One special exception is that if you specify a single unit name, and One special exception is that if you specify a single unit name, and
a compatible unit appears somewhere in the units expression, then a compatible unit appears somewhere in the units expression, then
that compatible unit will be converted to the new unit and the that compatible unit will be converted to the new unit and the
@ -35684,19 +35690,6 @@ as @samp{a/(b*c)}. If @code{calc-multiplication-has-precedence} is
of @code{calc-multiplication-has-precedence} is @code{t}. of @code{calc-multiplication-has-precedence} is @code{t}.
@end defvar @end defvar
@defvar calc-ensure-consistent-units
When converting units, the variable @code{calc-ensure-consistent-units}
determines whether or not the target units need to be consistent with the
original units. If @code{calc-ensure-consistent-units} is @code{nil}, then
the target units don't need to have the same dimensions as the original units;
for example, converting @samp{100 ft/s} to @samp{m} will produce @samp{30.48 m/s}.
If @code{calc-ensure-consistent-units} is non-@code{nil}, then the target units
need to have the same dimensions as the original units; for example, converting
@samp{100 ft/s} to @samp{m} will result in an error, since @samp{ft/s} and @samp{m}
have different dimensions. The default value of @code{calc-ensure-consistent-units}
is @code{nil}.
@end defvar
@defvar calc-context-sensitive-enter @defvar calc-context-sensitive-enter
The commands @code{calc-enter} and @code{calc-pop} will typically The commands @code{calc-enter} and @code{calc-pop} will typically
duplicate the top of the stack. If duplicate the top of the stack. If
@ -36497,6 +36490,7 @@ keystrokes are not listed in this summary.
@r{ defn@: u d @:unit, descr @: @:calc-define-unit@:} @r{ defn@: u d @:unit, descr @: @:calc-define-unit@:}
@r{ @: u e @: @: @:calc-explain-units@:} @r{ @: u e @: @: @:calc-explain-units@:}
@r{ @: u g @:unit @: @:calc-get-unit-definition@:} @r{ @: u g @:unit @: @:calc-get-unit-definition@:}
@r{ @: u n @:units @: 18 @:calc-convert-exact-units@:}
@r{ @: u p @: @: @:calc-permanent-units@:} @r{ @: u p @: @: @:calc-permanent-units@:}
@r{ a@: u r @: @: @:calc-remove-units@:} @r{ a@: u r @: @: @:calc-remove-units@:}
@r{ a@: u s @: @: @:usimplify@:(a)} @r{ a@: u s @: @: @:usimplify@:(a)}

View file

@ -1438,11 +1438,11 @@ as measured in the integer number of days before December 31, 1 BC (Gregorian)."
(defun calcFunc-unixtime (date &optional zone) (defun calcFunc-unixtime (date &optional zone)
(if (math-realp date) (if (math-realp date)
(progn (progn
(setq date (math-add 719164 (math-div date '(float 864 2)))) (setq date (math-add 719163 (math-div date '(float 864 2))))
(list 'date (math-sub date (math-div (calcFunc-tzone zone date) (list 'date (math-sub date (math-div (calcFunc-tzone zone date)
'(float 864 2))))) '(float 864 2)))))
(if (eq (car date) 'date) (if (eq (car date) 'date)
(math-add (nth 1 (math-date-parts (nth 1 date) 719164)) (math-add (nth 1 (math-date-parts (nth 1 date) 719163))
(calcFunc-tzone zone date)) (calcFunc-tzone zone date))
(math-reject-arg date 'datep)))) (math-reject-arg date 'datep))))