Skip to content

Commit

Permalink
Merge pull request #3663 from fable-compiler/feature/date_parse
Browse files Browse the repository at this point in the history
Work on DateTime for Python
  • Loading branch information
MangelMaxime authored Jan 23, 2024
2 parents 326048b + e331d04 commit a1434ff
Show file tree
Hide file tree
Showing 17 changed files with 1,818 additions and 207 deletions.
20 changes: 14 additions & 6 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN apt-get update && apt-get install -y xz-utils
# Let it here to avoid conflicts with Microsoft options !!!
ARG DOTNET_VERSION=8.0.100
ARG NODE_VERSION=18.8.0
ARG PYTHON_VERSION=3.11.5
ARG PYTHON_VERSION=3.10.0
ARG DART_VERSION=3.1.2

USER vscode
Expand All @@ -38,8 +38,20 @@ SHELL ["/bin/zsh", "-c"]
WORKDIR /home/vscode
RUN sudo apt install wget
RUN wget -qO- https://dot.net/v1/dotnet-install.sh | bash -s - --version $DOTNET_VERSION
# Because .NET doesn't setup the path for us, we need to do it
# Bash is the default shell for the dev container, we need it for the extensions
# to work properly
RUN echo "# Load dotnet path" >> .bashrc
RUN echo "export DOTNET_ROOT=/home/vscode/.dotnet" >> .bashrc
RUN echo 'export PATH=$PATH:$DOTNET_ROOT:~/.dotnet/tools' >> .bashrc
RUN echo 'export DOTNET_RUNNING_IN_CONTAINER=true' >> .bashrc
Run echo 'export DOTNET_USE_POLLING_FILE_WATCHER=true' >> .bashrc
# Zsh is the shell used by the user, so we need to setup the path for it too
RUN echo "# Load dotnet path" >> .zshrc
RUN echo "export PATH=$PATH:/home/vscode/.dotnet" >> .zshrc
RUN echo "export DOTNET_ROOT=/home/vscode/.dotnet" >> .zshrc
RUN echo 'export PATH=$PATH:$DOTNET_ROOT:~/.dotnet/tools' >> .zshrc
RUN echo 'export DOTNET_RUNNING_IN_CONTAINER=true' >> .zshrc
Run echo 'export DOTNET_USE_POLLING_FILE_WATCHER=true' >> .zshrc
# Trigger the dotnet first run experience by running a command
RUN source .zshrc && dotnet --help
# Add dotnet zsh completion
Expand All @@ -60,10 +72,6 @@ RUN echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" #
RUN source .zshrc && nvm install $NODE_VERSION

# Install python
# Install Python build dependencies
RUN sudo apt-get install -y build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
# Install pyenv
RUN curl https://pyenv.run | bash
RUN echo "# Load pyenv path" >> .zshrc
Expand Down
11 changes: 1 addition & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,7 @@
"tamasfe.even-better-toml"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
// I don't know why but Ionide and C# extension don't find
// the installed dotnet version.
// For Ionide, we guide it using the following setting
"FSharp.dotnetRoot": "/home/vscode/.dotnet",
// For C#, we disable the warning as we don't seems to need it.
// If this is a problem, we can probably use the C#/F# dockerfile
// as the base and keep our way to install the different target version
// .NET included to respect the global.json requirements
"csharp.suppressDotnetInstallWarning": true
"terminal.integrated.defaultProfile.linux": "zsh"
}
}
},
Expand Down
50 changes: 25 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 60 additions & 1 deletion src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Fixed nested type with custom hashcode (by @dbrattli)
* Add 'Double.IsPositiveInfinity' (by @PierreYvesR)
* [GH-3666](https://github.com/fable-compiler/Fable/pull/3666) Fix for `DateTime` and `TimeSpan` addition (by @dbrattli)
* [GH-3663](https://github.com/fable-compiler/Fable/pull/3663) Fix `DateTime.Parse` and `DateTime.TryParse` (by @MangelMaxime)

#### JavaScript

* Fix `DateTime.Parse` when providing a 1 digit hour for PM times (`3:5:34 PM`) (by @MangelMaxime)

#### Rust

Expand All @@ -40,6 +46,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [GH-3671](https://github.com/fable-compiler/Fable/pull/3671) Use `Microsoft.Extensions.Logging` (by @nojaf)

#### Dart

* Fix `DateTime.DayOfWeek` (by @MangelMaxime)

### Added

#### Python

* [GH-3663](https://github.com/fable-compiler/Fable/pull/3663) Complete rewrite of `DateTime` supports (by @MangelMaxime)

*Special thanks to @dbrattli and @ncave for their help*

* Constructors
* From `(year, month, day)` up to `(year, month, day, hour, minute, second, millisecond, microsecond)` (with and without `DateTimeKind`)
* From `ticks` (with and without `DateTimeKind`)
* Instance methods:
* `dt.Year`
* `dt.Month`
* `dt.Day`
* `dt.Hour`
* `dt.Minute`
* `dt.Second`
* `dt.Millisecond`
* `dt.Microsecond`
* `dt.ToUniversalTime`
* `dt.DayOfWeek`
* `dt.DayOfYear`
* `dt.ToShortDateString`
* `dt.ToShortTimeString`
* `dt.ToLongDateString`
* `dt.ToLongTimeString`
* `dt.ToString`
* `dt.ToLocalTime`
* `dt.Date`
* `dt.AddYears`
* `dt.AddMonths`
* `dt.AddDays`
* `dt.AddHours`
* `dt.AddMinutes`
* `dt.AddSeconds`
* `dt.AddMilliseconds`
* `dt.AddMicroseconds`
* `dt.Kind`
* Static methods:
* `DateTime.Today`
* `DateTime.Now`
* `DateTime.Now`
* `DateTime.UtcNow`
* `DateTime.MinValue`
* `DateTime.MaxValue`
* `DateTime.Parse`
* `DateTime.TryParse`
* `DateTime.SpecifyKind`

## 4.9.0 - 2023-12-14

### Fixed
Expand All @@ -48,7 +108,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [GH-3655](https://github.com/fable-compiler/Fable/issues/3655) Fix for Python output file names (by @dbrattli)
* [GH-3660](https://github.com/fable-compiler/Fable/issues/3660) Fix for decimal to string with culture (by @dbrattli)
* [GH-3666](https://github.com/fable-compiler/Fable/pull/3666) Fix for `DateTime` and `TimeSpan` addition (by @dbrattli)

## 4.8.1 - 2023-12-12

Expand Down
94 changes: 82 additions & 12 deletions src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4957,6 +4957,56 @@ let debug
IfThenElse(cond, makeDebugger r, unit, r) |> Some
| _ -> None

let private ignoreFormatProvider
com
(ctx: Context)
r
(moduleName: string)
meth
args
=
match meth, args with
// Ignore IFormatProvider
| "Parse", arg :: _culture :: _styles :: _ ->
addWarning
com
ctx.InlinePath
r
$"%s{moduleName}.Parse will ignore culture and styles"

[ arg ]
| "Parse", arg :: _culture :: _ ->
addWarning
com
ctx.InlinePath
r
$"%s{moduleName}.Parse will ignore culture"

[ arg ]
| "TryParse", input :: _culture :: _styles :: defVal :: _ ->
addWarning
com
ctx.InlinePath
r
$"%s{moduleName}.TryParse will ignore culture and styles"

[
input
defVal
]
| "TryParse", input :: _culture :: defVal :: _ ->
addWarning
com
ctx.InlinePath
r
$"%s{moduleName}.TryParse will ignore culture"

[
input
defVal
]
| _ -> args

let dates
(com: ICompiler)
(ctx: Context)
Expand Down Expand Up @@ -5013,12 +5063,41 @@ let dates
let args =
(List.take 6 args)
@ [
makeIntConst 0
makeIntConst 0
last
]

let argTypes =
(List.take 6 i.SignatureArgTypes)
@ [
Int32.Number
Int32.Number
last.Type
]

Helper.LibCall(
com,
"Date",
"create",
t,
args,
argTypes,
?loc = r
)
|> Some
| 8, Number(_, NumberInfo.IsEnum ent) when
ent.FullName = "System.DateTimeKind"
->
let args =
(List.take 7 args)
@ [
makeIntConst 0
last
]

let argTypes =
(List.take 7 i.SignatureArgTypes)
@ [
Int32.Number
last.Type
Expand Down Expand Up @@ -5057,7 +5136,6 @@ let dates
?loc = r
)
|> Some
| "get_Kind"
| "get_Offset" ->
Naming.removeGetSetPrefix i.CompiledName
|> Naming.lowerFirst
Expand Down Expand Up @@ -5150,17 +5228,6 @@ let dates
[ ms ]

Helper.LibCall(com, "Long", "fromNumber", t, args, ?loc = r) |> Some
| "get_Ticks" ->
Helper.LibCall(
com,
"Date",
"getTicks",
t,
[ thisArg.Value ],
[ thisArg.Value.Type ],
?loc = r
)
|> Some
| "get_UtcTicks" ->
Helper.LibCall(
com,
Expand Down Expand Up @@ -5219,6 +5286,9 @@ let dates
|> Some
| _ -> None
| meth ->
let args =
ignoreFormatProvider com ctx r i.DeclaringEntityFullName meth args

let meth = Naming.removeGetSetPrefix meth |> Naming.lowerFirst

Helper.LibCall(
Expand Down
2 changes: 1 addition & 1 deletion src/fable-library-dart/Date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ int day(DateTime d) => d.day;
int hour(DateTime d) => d.hour;
int minute(DateTime d) => d.minute;
int millisecond(DateTime d) => d.millisecond;
int dayOfWeek(DateTime d) => d.weekday;
int dayOfWeek(DateTime d) => d.weekday % 7;

int dayOfYear(DateTime d) {
final _year = d.year;
Expand Down
Loading

0 comments on commit a1434ff

Please sign in to comment.