Abstracts for time units?

62 views
Skip to first unread message

Dion Whitehead Amago

unread,
Feb 3, 2016, 7:04:48 PM2/3/16
to Haxe
It can be confusing dealing with time. Specifically, haxe.Timer.stamp() uses seconds, however most time stamps in Javascript use millisecond time units.

It might help to use an abstract, e.g. TimeMilleseconds or TimeSeconds to have the compiler automatically check for these kinds of mistakes.

Would there be any interest in this kind of use case, or is it abstract overkill?

Raoul Duke

unread,
Feb 3, 2016, 7:06:54 PM2/3/16
to haxe...@googlegroups.com
i personally very much <heart> that kind of careful use of types.

Justin L Mills

unread,
Feb 3, 2016, 7:50:20 PM2/3/16
to haxe...@googlegroups.com
Science defines time from the second so that's probably more fundimental
than just fitting with Javascript, but using an Int obviously has lots
of savings so on perfornance grounds milisecond seems attractive.

Looking at haxe.Timer I have to admit that it seems inconsistant
flirting between miliseconds and seconds.

http://api.haxe.org/haxe/Timer.html

but I guess in some situations it would be easy to have dual methods.

haxe.Timer.secStamp();
haxe.Timer.miliSecStamp();


might be quite
> --
> To post to this group haxe...@googlegroups.com
> http://groups.google.com/group/haxelang?hl=en
> ---
> You received this message because you are subscribed to the Google
> Groups "Haxe" group.
> For more options, visit https://groups.google.com/d/optout.

Will Maynard

unread,
Feb 3, 2016, 7:59:48 PM2/3/16
to Haxe
"Science defines time from the second"

...What?

Franco Ponticelli

unread,
Feb 3, 2016, 10:13:44 PM2/3/16
to Haxe

Justin L Mills

unread,
Feb 4, 2016, 6:57:38 PM2/4/16
to haxe...@googlegroups.com
Franco very extensive :)

On 04/02/2016 00:59, Will Maynard wrote:
"Science defines time from the second"

...What?
to Clarify Will question on my point.

The second is not a very logical measurement of time being originally related to the rotation of the earth and now...

"the duration of 9 192 631 770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the caesium 133 atom." - npl.co.uk

But it is the base SI unit of time used in science and engineering, adding a letter to denote the number of zeros is common such as with ms, but it is the second, that is the base unit of science and engineering not the ms there are loads of links but here is one.

http://www.science.uwaterloo.ca/~cchieh/cact/c120/siunits.html

Perhaps a less intuative measurement of time that is more linked to the physics of the world, is the Planck time, which likely used is some partical physics but not so much in general engineering on our macro scale. 

https://en.wikipedia.org/wiki/Planck_time

So my point that Javascript using the 'ms' was kind of arbitary and irrational in some respects and certainly should not be a good reason in itself being like America still using the Inch ( just to f up the odd space calculation every now and then ) or here in England using the Pint and Mile.  Measurement standards are important because they make sure that calculations and science work the same the world over.

Justin L Mills

unread,
Feb 4, 2016, 7:40:28 PM2/4/16
to haxe...@googlegroups.com
Franco

I was wondering if you had thought about SI prefixes, I see some in your code but it seems mixed with other systems so is a bit confusing.

https://en.wikipedia.org/wiki/Metric_prefix#List_of_SI_prefixes

It suppose it would be simple to create abstracts

var x: hecto = 1;
trace( x ); // 100

but it might be a hassle to define all mappings and conversions?

var x0: hecto = 1;
var x1: mega = 1;
trace( x0 * x1 ); // 100000000

var y0: hecto = 1;
var y1: mega = y0;
trace( y1 ); // 0.1

Or is something to make this easy implemented in Haxe already?  Have you made SI prefixes abstracts?

Best

Justin

Franco Ponticelli

unread,
Feb 4, 2016, 10:48:52 PM2/4/16
to haxe...@googlegroups.com
I did not but we could. The code for thx.unit is generated so adding new definitions is definitely not bad. I will think about. One thing I definitely would like to do is composite units like m/s.
Reply all
Reply to author
Forward
0 new messages