scratchfoundation / scratch-vm

Virtual Machine used to represent, run, and maintain the state of programs for Scratch 3.0
http://scratchfoundation.github.io/scratch-vm/
BSD 3-Clause "New" or "Revised" License
1.21k stars 1.5k forks source link

Day since 2000 code? #268

Closed CosmicWebServices closed 7 years ago

CosmicWebServices commented 7 years ago

This is the discussion talking about #272

tmickel commented 7 years ago

@CosmicWebServices Thanks. We'd be happy to take a PR that implements the block, or we'll get around to it eventually.

Please check out the scratch-flash implementation: https://github.com/LLK/scratch-flash/blob/master/src/primitives/SensingPrims.as#L306

If possible, we should have the same behavior for timezones.

Regarding decimal precision: seems fine to me to have extra precision, but I haven't thought about it carefully.

CosmicWebServices commented 7 years ago

OK thanks maybe when I figure out how to do it I will

CosmicWebServices commented 7 years ago

Sorry for the late reply I will work o a pr soon

towerofnix commented 7 years ago

seems fine to me to have extra precision

The more precise the days-since-2000 block, the better. It's already crazy (and for good reason - it's a super handy block), going farther isn't going overboard!

IMO.

By the way.. I haven't checked, but does scratch-blocks limit the rendered digits of a reporter block's result bubble?

CosmicWebServices commented 7 years ago

So I should leave the extra digets?

tmickel commented 7 years ago

@liam4 If I remember right, as far as scratch-blocks is concerned, the bubble isn't limited and can display arbitrary HTML. @CosmicWebServices Yes, that seems fine to me.

towerofnix commented 7 years ago

I feel taken technically :)

I suppose that if it does (or would) do anything, that's in scratch-vm? (i.e. snipping digits from number bubble returns)

dekrain commented 7 years ago

@CosmicWebServices You must rewrite https://github.com/LLK/scratch-vm/blob/develop/src/blocks/scratch3_sensing.js#L26 adding comma and on next line, add

'sensing_dayssince2000': this.daysSince2000

Next add on end of file, before module.exports something like:

Scratch3SensingBlocks.prototype.daysSince2000 = function() {
  var start = new Date(2000, 1-1, 1); 
  var today =   new Date(); 
  return (today.valueOf() - start.valueOf()) / 1000 / 86400;
}
CosmicWebServices commented 7 years ago

Thanks @dekrain when I am done school I will do that.

CosmicWebServices commented 7 years ago

nvm I will do it now

CosmicWebServices commented 7 years ago

The pr is at #272

CosmicWebServices commented 7 years ago

@liam4 or anyone else do you think the extra few decimal places with hurt cross-compatibility?

towerofnix commented 7 years ago

Nah. I don't know why anybody would need to e.g. check the length of the return value of days since 2000..

CosmicWebServices commented 7 years ago

Actually some people used that in my pen challenge also the one line challenge but I think it is fine still.