Giter VIP home page Giter VIP logo

Comments (3)

martijn avatar martijn commented on July 17, 2024

There is currently no way of doing this. By design Xsv returns arrays of parsed primitives instead of proxy objects. The parsing for a 'd' type cell happens in

when "d"
DateTime.parse(@current_value)

Perhaps you can reverse the effect of DateTime.parse in your code?

from xsv.

iuri-gg avatar iuri-gg commented on July 17, 2024

I cannot reverse it because I am getting the Date object, not DateTime. Even though the underlying raw value has a time component saved, I am not getting datetime back because the cell is formatted as Date in xlsx. If I open xlsx file and change cell format to DateTime, then I get datetime value from xsv too. However those files are exported from a different system that I don't have control of so I need a way to either to override cell style/format or get access to raw value and convert it to datetime myself.

from xsv.

martijn avatar martijn commented on July 17, 2024

Ah, I forgot that exists. Indeed what you have is a number formatted as a date. The conversion is done by adding the number value to an epoch.

    EPOCH = Date.new(1899, 12, 30).freeze

    def parse_date(number)
      EPOCH + number
    end

This can be reversed:

irb(main):018:0> excel_value = 123.45
irb(main):019:0> parsed = parse_date(excel_value)
=> #<Date: 1900-05-02 ((2415142j,38880s,0n),+0s,2299161j)>
irb(main):020:0> (parsed-EPOCH).to_f
=> 123.45

I hope that helps! It would be interesting idea to add a middleware pipeline to Xsv to customize the parsing, but I have no time to build that. PR's are always welcome, though!

from xsv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.