-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
147 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,70 @@ | ||
module FsSpreadsheet.Json.Value | ||
|
||
open Thoth.Json.Core | ||
open FsSpreadsheet | ||
|
||
#if FABLE_COMPILER_PYTHON | ||
module PyTime = | ||
|
||
open Fable.Core | ||
open Fable.Core.PyInterop | ||
|
||
// Currently in Fable, a created datetime object will contain a timezone. This is not allowed in python xlsx, so we need to remove it. | ||
// Unfortunately, the timezone object in python is read-only, so we need to create a new datetime object without timezone. | ||
// For this, we use the fromtimestamp method of the datetime module and convert the timestamp to a new datetime object without timezone. | ||
|
||
type DateTimeStatic = | ||
[<Emit("$0.fromtimestamp(timestamp=$1)")>] | ||
abstract member fromTimeStamp: timestamp:float -> System.DateTime | ||
|
||
[<Import("datetime", "datetime")>] | ||
let DateTime : DateTimeStatic = nativeOnly | ||
|
||
let toUniversalTimePy (dt:System.DateTime) = | ||
|
||
dt.ToUniversalTime()?timestamp() | ||
|> DateTime.fromTimeStamp | ||
#endif | ||
|
||
|
||
|
||
|
||
|
||
module Decode = | ||
|
||
let datetime: Decoder<System.DateTime> = | ||
#if FABLE_COMPILER_PYTHON | ||
Decode.datetimeLocal |> Decode.map PyTime.toUniversalTimePy | ||
#else | ||
{ new Decoder<System.DateTime> with | ||
member _.Decode(helpers, value) = | ||
if helpers.isString value then | ||
match System.DateTime.TryParse(helpers.asString value) with | ||
| true, datetime -> datetime |> Ok | ||
| _ -> ("", BadPrimitive("a datetime", value)) |> Error | ||
else | ||
("", BadPrimitive("a datetime", value)) |> Error | ||
} | ||
#endif | ||
|
||
let encode (value : obj) = | ||
match value with | ||
| :? string as s -> Encode.string s | ||
| :? int as i -> Encode.int i | ||
| :? float as f -> Encode.float f | ||
| :? int as i -> Encode.int i | ||
| :? bool as b -> Encode.bool b | ||
| :? System.DateTime as d -> Encode.datetime d | ||
| :? System.DateTime as d -> | ||
d.ToString("O", System.Globalization.CultureInfo.InvariantCulture).Split('+').[0] | ||
|> Encode.string | ||
| _ -> Encode.nil | ||
|
||
let decode : Decoder<obj> = | ||
|
||
|
||
let decode = | ||
Decode.oneOf [ | ||
Decode.string |> Decode.map (fun s -> s :> obj) | ||
Decode.int |> Decode.map (fun i -> i :> obj) | ||
Decode.float |> Decode.map (fun f -> f :> obj) | ||
Decode.bool |> Decode.map (fun b -> b :> obj) | ||
Decode.datetimeLocal |> Decode.map (fun d -> d :> obj) | ||
Decode.bool |> Decode.map (fun b -> b :> obj, DataType.Boolean) | ||
Decode.int |> Decode.map (fun i -> i :> obj, DataType.Number) | ||
Decode.float |> Decode.map (fun f -> f :> obj, DataType.Number) | ||
Decode.datetime |> Decode.map (fun d -> d :> obj, DataType.Date) | ||
Decode.string |> Decode.map (fun s -> s :> obj, DataType.String) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
module FsSpreadsheet.Net.Tests | ||
open Expecto | ||
|
||
open Fable.Pyxpecto | ||
open TestingUtils | ||
|
||
let all = | ||
testList "All" | ||
[ | ||
ZipArchiveReader.main | ||
Stylesheet.main | ||
DefaultIO.main | ||
FsExtension.Tests.main | ||
Cell.Tests.main | ||
Sheet.Tests.main | ||
Workbook.Tests.main | ||
Spreadsheet.Tests.main | ||
Table.Tests.main | ||
FsWorkbook.Tests.main | ||
Json.Tests.main | ||
] | ||
|
||
[<EntryPoint>] | ||
let main argv = | ||
Tests.runTestsInAssemblyWithCLIArgs [] argv | ||
Pyxpecto.runTests [||] all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.