Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on DateTime for Python #3663

Merged
merged 31 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0dabaac
WIP: DateTime.Parse
MangelMaxime Dec 14, 2023
c806bc2
Fix DateTime.DayOfWeek for Dart
MangelMaxime Dec 14, 2023
9fc2166
Work on improving date.py
MangelMaxime Dec 14, 2023
259f4c2
Remove python-dateutil from dependencies
MangelMaxime Dec 14, 2023
dfac153
Fix iso format parsing for Python 3.10
dbrattli Dec 16, 2023
5829de6
Update the changelog
MangelMaxime Jan 2, 2024
77ce868
Apply ruff format to fable-library-py
MangelMaxime Jan 2, 2024
2d0fe66
Ignore culture/styles for DateTime.Parse/TryParse
MangelMaxime Jan 2, 2024
f22ce40
Save progress made on date.py
MangelMaxime Jan 2, 2024
405fcd0
Fix tests as we can't hard code the expected value for time-only Date…
MangelMaxime Jan 3, 2024
5931432
Fix `DateTime.Parse` when providing a 1 digit hour for PM times (`3:5…
MangelMaxime Jan 4, 2024
9ed34b4
Fix `DateTime.Parse` when providing a 1 digit hour for PM times (`3:5…
MangelMaxime Jan 4, 2024
6feffb4
More improvements / fixes to date.yp
MangelMaxime Jan 6, 2024
a7848c1
Fix some test by using non breaking space + Fix DateTimeKind support
MangelMaxime Jan 9, 2024
104e2f8
Make LocalTimezone supports daylight saving when computing utcoffset
MangelMaxime Jan 9, 2024
d278f36
Debug which culture info is used on the CI
MangelMaxime Jan 9, 2024
56fae58
Fix formatting of the date to use invariant culture info setup (Fable…
MangelMaxime Jan 9, 2024
cc87921
Implements custom date supports
MangelMaxime Jan 19, 2024
5fb5762
Add supports for microseconds precision in the constructor / from_ticks
MangelMaxime Jan 22, 2024
3c2ec1e
Bump poetry dependencies version
MangelMaxime Jan 22, 2024
3db5e9e
Take into account remark from @dbrattli
MangelMaxime Jan 22, 2024
a3a8052
Disable a portion of DateTime.SpecifyKind which fails on .NET runtime…
MangelMaxime Jan 22, 2024
924e5ba
Reset quicktest.fsx file
MangelMaxime Jan 22, 2024
ff73ee6
Fix devcontainer setup to better configure .NET and fix Python instal…
MangelMaxime Jan 22, 2024
3915200
Fix iso date format supports for Python 3.10.0
MangelMaxime Jan 22, 2024
8245820
Disable a specific test which fails because Python on windows require…
MangelMaxime Jan 22, 2024
bb74243
Fix custom format "y" for Windows runtime
MangelMaxime Jan 22, 2024
c0571aa
Update list of exposed functions + fix create calls to forward the mi…
MangelMaxime Jan 22, 2024
93d474f
Resolve problems mentioned by @dbrattli
MangelMaxime Jan 23, 2024
04777d5
Update changelog and add special thanks
MangelMaxime Jan 23, 2024
e331d04
Fix F# analysers warning
MangelMaxime Jan 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -17,13 +17,73 @@ 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

* Fixed unary negation for signed integer MinValue (by @ncave)
* Fixed excluding signature files from imports (by @ncave)
* Fixed generic try_catch closure trait (by @ncave)

#### 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 @@ -32,7 +92,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 @@ -4953,6 +4953,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 @@ -5009,12 +5059,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 @@ -5053,7 +5132,6 @@ let dates
?loc = r
)
|> Some
| "get_Kind"
| "get_Offset" ->
Naming.removeGetSetPrefix i.CompiledName
|> Naming.lowerFirst
Expand Down Expand Up @@ -5146,17 +5224,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 @@ -5215,6 +5282,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
Loading