Comments (14)
It might be a good idea to have a flexible type (custom epoch and resolution), like:
type: timestamp
timestamp-type: u4
unit: 1 for seconds, 10**-6 for nanoseconds, a float value
epoch: 1970 for unix epoch, an integer value
from kaitai_struct_webide.
I am more or less familiar with those issues. But that should not be a reason to not add it. After all, adding a type does not restrict the users but expands their capability. If they dont want to use the corresponding target type (due to multiple possible reasons) they can just parse Int32 and thats it. Having multiple possible implementations, its better to offer one than none. Languages that dont have any, like C, can just parse the int as well.
Construct has a flexible format, Timestamp works by parsing chosen subcon (Int32ul for example) then interprets it as a total seconds/microseconds/nanoseconds (chosen) since epoch (chosen). Of course the Arrow module might not support some values (subcon range outside of Arrow range), floating-point errors, etc. But it works with reasonable dates and reasonable precision.
from kaitai_struct_webide.
please, Windows FILETIME (u64le of microseconds from 1601-01-01 00:00).
from kaitai_struct_webide.
there goes MS FILETIME:
...
var u64le = Converter.numConv(data, 8, false, false);
this.msfiletime = u64le ? dateFormat(new Date(parseInt(u64le)/10000 - 11644473600000), "yyyy-mm-dd HH:MM:ss") : "";
...
number 11644473600000
above is the difference of unix and MS filetime epoch (1970-01-01T00:00:00 - 1601-01-01T00:00:00) in milliseconds.
I think similar trick can be used for Mac and Windows Float type timestamps:
http://www.silisoftware.com/tools/date.php
from kaitai_struct_webide.
I guess converter should not have hardcoded formats, but should have a setting to try arbitrary ksy descriptions against the fields of suitable size.
from kaitai_struct_webide.
- there are finite number of datestamps andf ortunately/unfortunately they are very commonly used in the binary formats. 2) I see no posibilty of conversion binary datastamp in language-agnost way using ksy-alone into human readable datetime format. While technically it is possible, it would be not efficient compared to usig builtin datestamp conversion language specific methods. Our planets revolution around the sun is quite messed... unless timestamp will get same love as zlib in ksy.
That needs some research and erfort to work across different langueges consistently. Unfortunately languages treat datetime types with different precissions, which begs to ask if exact implementation should be not left for particular user case. In the end, whole tab is very helpful when RE. the clutter could be managed by options, pull down selection: eg. only one endiannes (le or be); only one timestamp format. when there would be some place for eventual ksy defined types too.
from kaitai_struct_webide.
There might be some connection of this and kaitai-io/kaitai_struct#188, but in general, there's little connection with ksy specs so far. Many timestamps are just integers that specify number of (seconds|microseconds|nanoseconds|etc) that passed since some arbitrary date.
from kaitai_struct_webide.
I've posted a list of timestamps info I've collected, please take a look.
from kaitai_struct_webide.
wow, that's an extensive list!
from kaitai_struct_webide.
IMHO
1 we should not spoil syntax with everything possible.
2 every machine-readable date/time format can be converted into an integer ...
3 ... or parsed from an integer
4 instances and params are all what we need
so,
5 we don't need any additional syntax for timestamps, timestamp is just an uint offsetted to a standardized offset, I think we should stick to a single standard
6 and we don't even need additional types: we already have uints, I guess hints should be enough in for display purposes, but for another ones not covered we can implement the computation right in KS and put the type into the stdlib.
from kaitai_struct_webide.
I thought of trying to add a "timestamp" / "datetime" data type, either abstract or concrete, and so far it looks like problems outweight potential benefits by a large margin.
For starters, quite a few languages lack definitive timestamp data types at all. Sometimes, there are several competing standards. Those who have such data types, are quite often restricted by a particular implementation:
- range
- precision
- with / without timezone
- how it works with ancient dates (i.e. pre-Gregorian calendar approximations)
- ability to represent stuff like
1970-00-01
or1970-01-00
or1970-12-32
So, typically, at best we can do some approximation, yet lots of application require exact precision (for reproducibility, in-domain calculations, etc).
Probably this could be mediated by creation of something like "Kaitai DateTime", which would offer the same exact interface, built-in support for lots of possible time formats, and an ability to export into target language's timestamp formats, but this also has its cons and is obviously a huge undertaking.
from kaitai_struct_webide.
timestamp-type: u4
is not a new type, it's new syntax
I expect using timestamps as
seq:
- id: ts_
type: s8
instances:
ts:
type: timestamp(ts_, ...other parameters needed)
note that we don't have typed instances for now
from kaitai_struct_webide.
Construct has a flexible format, Timestamp works by parsing chosen subcon (Int32ul for example) then interprets it as a total seconds/microseconds/nanoseconds (chosen) since epoch (chosen). Of course the Arrow module might not support some values (subcon range outside of Arrow range), floating-point errors, etc.
I don't think that Construct's Timestamp is a good idea to copy for several reasons:
- It supports only single integer-based timestamps, i.e. no per-component timestamps, no approximate timestamps, etc.
- It depends on one particular non-standard library; most languages lack something similar, and even for Python folks, I'm not 100% sure that everyone would be happy with adding Arrow to their project
- Instead of decoupling time stamp definition into some kind of library, you're forced to repeat that "epoch = 1970, precision = 1s", or "epoch = 1601, precision = 100ns" every time. A single typo (like typing "1600" instead of "1601") or something, and, boom, you've got a weird parsing error that would be very hard to find, as only one of possible hundreds of definitions in a format would be slightly off in some cases.
But it works with reasonable dates and reasonable precision.
The problem is that in binary formats world, people tend to use bizzare magical values and stuff like that. For example, "all 0s" and "all 1s" are popular choices that you quite often need to be able to represent exactly, as they have some special meaning like "time unknown", "this entity is void" or something like that. For these, you can't go with approximates.
from kaitai_struct_webide.
Would it be possible to make this a -webide-representation
feature? I see the issue with putting it in the parser – better to have user code handle it – but most of the above formats could be quite easily displayed as ISO or localized strings. Having the tag in the ksy could also help document the raw type. Something like
{unix:timestamp=s/1970-01-01}
(or ms etc){msfiletime:timestamp=100ns/1601-01-01}
{webkit:timestamp=us/1601}
(iso8601 doesn't require-MM-DD
){cocoa:timestamp=s/2001}
{hfs:timestamp=s/1904}
{mysql:timestamp=s/0000}
{excel:timestamp=day/1899-12-31}
day
could be given as 86400s
, s
as 1s
or even 1us
as 0.000001
(s
) to simplify implementation.
I don't see the point in it for fields of separate components, which can already be formatted and viewed easily.
FAT
# size: 4
# bit-endian: le
- id: secs
type: b5
- id: mins
type: b6
- id: hours
type: b5
- id: day
type: b5
- id: month
type: b4
- id: year
type: b7
SYSTEMTIME
# all with type: u4
- id: year
- id: month
- id: weekday
- id: day
- id: hour
- id: min
- id: sec
- id: milli
ISO9660
# encoding: ASCII
- id: year
size: 4
type: str
- id: month
size: 2
type: str
- id: day
size: 2
type: str
- id: hour
size: 2
type: str
- id: min
size: 2
type: str
- id: sec
size: 2
type: str
- id: centi
size: 2
type: str
- id: utc_offset
type: s1
from kaitai_struct_webide.
Related Issues (20)
- Non-descriptive error messages
- Display TLV Formats in Object Tree HOT 1
- Enums bugs HOT 3
- Missing link to user manual HOT 4
- [feature suggestion] Autorun HOT 2
- "Parse error (RangeError): invalid or out-of-range index" after changing KSY in editor HOT 1
- `-webide-representation` key not working for imported types HOT 1
- Parse error (TypeError): ksyType.instancesByJsName is undefined
- Strings in UTF-16 encodings does not decoded correctly HOT 3
- Long (?) binary data exported in JSON as `{ "$start": x, "$end": y }` instead of an array
- Add ability to inject custom JS code for processors HOT 2
- Feature request: update object-tree selection on keyboard navigation
- "unable to find enum member" when using binary notation HOT 2
- Ability to create link to IDE with custom urls for format specification and binary file HOT 2
- `to-string` is broken: `Parse error (TypeError): ksyType.instancesByJsName is undefined`
- Feature request: although parsing has failed, show all the parsed tree till the fail HOT 2
- electron (or equivalent) build for local desktop use? HOT 1
- Distribute kaitai_struct_webide as Electron application and npm module HOT 6
- Empty object tree and error on opening ide with zip example HOT 3
- `-webide-representation` doesn't work for arrays of primitive values HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kaitai_struct_webide.