mirror of
https://github.com/tiennm99/time-mocker.git
synced 2026-10-11 03:13:47 +00:00
Clear and rewrite
This commit is contained in:
1 parent
74150bdc5e
commit
57aaf45d11
7 files changed
-810
No files matched your search
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"mcp__acp__Bash",
|
||||
"mcp__acp__Edit"
|
||||
]
|
||||
}
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
# If you prefer the allow list template instead of the deny list, see community template:
|
||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||
#
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Code coverage profiles and other test artifacts
|
||||
*.out
|
||||
coverage.*
|
||||
*.coverprofile
|
||||
profile.cov
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
vendor/
|
||||
|
||||
# Go workspace file
|
||||
go.work
|
||||
go.work.sum
|
||||
|
||||
# env file
|
||||
.env
|
||||
|
||||
# Editor/IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
@@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -1,27 +0,0 @@
|
||||
# time-changer
|
||||
|
||||
GUI tool written in Go (Fyne) to change the Windows system time from the desktop.
|
||||
|
||||
> **Note:** Must be run as Administrator — Windows requires elevated privileges to set the system clock.
|
||||
|
||||
## Quick start
|
||||
|
||||
```bash
|
||||
go build -o time-changer.exe .
|
||||
# Right-click → Run as Administrator:
|
||||
time-changer.exe
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The app presents a calendar and time picker. Select the target date and time, then confirm to apply it as the new system time.
|
||||
|
||||
Supported date selection: year/month/day via calendar widget; hours, minutes, seconds via dropdowns.
|
||||
|
||||
## Related
|
||||
|
||||
- [time-mocker](https://github.com/tiennm99/time-mocker) — injects fake time into a running process without changing the system clock (different approach to the same problem of time-dependent testing).
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0 — see [LICENSE](LICENSE).
|
||||
@@ -1,40 +0,0 @@
|
||||
module github.com/tiennm99/time-changer
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require fyne.io/fyne/v2 v2.7.2
|
||||
|
||||
require (
|
||||
fyne.io/systray v1.12.0 // indirect
|
||||
github.com/BurntSushi/toml v1.5.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fredbi/uri v1.1.1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/fyne-io/gl-js v0.2.0 // indirect
|
||||
github.com/fyne-io/glfw-js v0.3.0 // indirect
|
||||
github.com/fyne-io/image v0.1.1 // indirect
|
||||
github.com/fyne-io/oksvg v0.2.0 // indirect
|
||||
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 // indirect
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
|
||||
github.com/go-text/render v0.2.0 // indirect
|
||||
github.com/go-text/typesetting v0.2.1 // indirect
|
||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||
github.com/hack-pad/go-indexeddb v0.3.2 // indirect
|
||||
github.com/hack-pad/safejs v0.1.0 // indirect
|
||||
github.com/jeandeaual/go-locale v0.0.0-20250612000132-0ef82f21eade // indirect
|
||||
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
||||
github.com/nicksnyder/go-i18n/v2 v2.5.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rymdport/portal v0.4.2 // indirect
|
||||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
|
||||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
|
||||
github.com/stretchr/testify v1.11.1 // indirect
|
||||
github.com/yuin/goldmark v1.7.8 // indirect
|
||||
golang.org/x/image v0.44.0 // indirect
|
||||
golang.org/x/net v0.57.0 // indirect
|
||||
golang.org/x/sys v0.47.0 // indirect
|
||||
golang.org/x/text v0.40.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
@@ -1,80 +0,0 @@
|
||||
fyne.io/fyne/v2 v2.7.2 h1:XiNpWkn0PzX43ZCjbb0QYGg1RCxVbugwfVgikWZBCMw=
|
||||
fyne.io/fyne/v2 v2.7.2/go.mod h1:PXbqY3mQmJV3J1NRUR2VbVgUUx3vgvhuFJxyjRK/4Ug=
|
||||
fyne.io/systray v1.12.0 h1:CA1Kk0e2zwFlxtc02L3QFSiIbxJ/P0n582YrZHT7aTM=
|
||||
fyne.io/systray v1.12.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
|
||||
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g=
|
||||
github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw=
|
||||
github.com/fredbi/uri v1.1.1 h1:xZHJC08GZNIUhbP5ImTHnt5Ya0T8FI2VAwI/37kh2Ko=
|
||||
github.com/fredbi/uri v1.1.1/go.mod h1:4+DZQ5zBjEwQCDmXW5JdIjz0PUA+yJbvtBv+u+adr5o=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/fyne-io/gl-js v0.2.0 h1:+EXMLVEa18EfkXBVKhifYB6OGs3HwKO3lUElA0LlAjs=
|
||||
github.com/fyne-io/gl-js v0.2.0/go.mod h1:ZcepK8vmOYLu96JoxbCKJy2ybr+g1pTnaBDdl7c3ajI=
|
||||
github.com/fyne-io/glfw-js v0.3.0 h1:d8k2+Y7l+zy2pc7wlGRyPfTgZoqDf3AI4G+2zOWhWUk=
|
||||
github.com/fyne-io/glfw-js v0.3.0/go.mod h1:Ri6te7rdZtBgBpxLW19uBpp3Dl6K9K/bRaYdJ22G8Jk=
|
||||
github.com/fyne-io/image v0.1.1 h1:WH0z4H7qfvNUw5l4p3bC1q70sa5+YWVt6HCj7y4VNyA=
|
||||
github.com/fyne-io/image v0.1.1/go.mod h1:xrfYBh6yspc+KjkgdZU/ifUC9sPA5Iv7WYUBzQKK7JM=
|
||||
github.com/fyne-io/oksvg v0.2.0 h1:mxcGU2dx6nwjJsSA9PCYZDuoAcsZ/OuJlvg/Q9Njfo8=
|
||||
github.com/fyne-io/oksvg v0.2.0/go.mod h1:dJ9oEkPiWhnTFNCmRgEze+YNprJF7YRbpjgpWS4kzoI=
|
||||
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 h1:5BVwOaUSBTlVZowGO6VZGw2H/zl9nrd3eCZfYV+NfQA=
|
||||
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-text/render v0.2.0 h1:LBYoTmp5jYiJ4NPqDc2pz17MLmA3wHw1dZSVGcOdeAc=
|
||||
github.com/go-text/render v0.2.0/go.mod h1:CkiqfukRGKJA5vZZISkjSYrcdtgKQWRa2HIzvwNN5SU=
|
||||
github.com/go-text/typesetting v0.2.1 h1:x0jMOGyO3d1qFAPI0j4GSsh7M0Q3Ypjzr4+CEVg82V8=
|
||||
github.com/go-text/typesetting v0.2.1/go.mod h1:mTOxEwasOFpAMBjEQDhdWRckoLLeI/+qrQeBCTGEt6M=
|
||||
github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066 h1:qCuYC+94v2xrb1PoS4NIDe7DGYtLnU2wWiQe9a1B1c0=
|
||||
github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o=
|
||||
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y=
|
||||
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
|
||||
github.com/hack-pad/go-indexeddb v0.3.2 h1:DTqeJJYc1usa45Q5r52t01KhvlSN02+Oq+tQbSBI91A=
|
||||
github.com/hack-pad/go-indexeddb v0.3.2/go.mod h1:QvfTevpDVlkfomY498LhstjwbPW6QC4VC/lxYb0Kom0=
|
||||
github.com/hack-pad/safejs v0.1.0 h1:qPS6vjreAqh2amUqj4WNG1zIw7qlRQJ9K10eDKMCnE8=
|
||||
github.com/hack-pad/safejs v0.1.0/go.mod h1:HdS+bKF1NrE72VoXZeWzxFOVQVUSqZJAG0xNCnb+Tio=
|
||||
github.com/jeandeaual/go-locale v0.0.0-20250612000132-0ef82f21eade h1:FmusiCI1wHw+XQbvL9M+1r/C3SPqKrmBaIOYwVfQoDE=
|
||||
github.com/jeandeaual/go-locale v0.0.0-20250612000132-0ef82f21eade/go.mod h1:ZDXo8KHryOWSIqnsb/CiDq7hQUYryCgdVnxbj8tDG7o=
|
||||
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 h1:YLvr1eE6cdCqjOe972w/cYF+FjW34v27+9Vo5106B4M=
|
||||
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25/go.mod h1:kLgvv7o6UM+0QSf0QjAse3wReFDsb9qbZJdfexWlrQw=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/nicksnyder/go-i18n/v2 v2.5.1 h1:IxtPxYsR9Gp60cGXjfuR/llTqV8aYMsC472zD0D1vHk=
|
||||
github.com/nicksnyder/go-i18n/v2 v2.5.1/go.mod h1:DrhgsSDZxoAfvVrBVLXoxZn/pN5TXqaDbq7ju94viiQ=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA=
|
||||
github.com/pkg/profile v1.7.0/go.mod h1:8Uer0jas47ZQMJ7VD+OHknK4YDY07LPUC6dEvqDjvNo=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rymdport/portal v0.4.2 h1:7jKRSemwlTyVHHrTGgQg7gmNPJs88xkbKcIL3NlcmSU=
|
||||
github.com/rymdport/portal v0.4.2/go.mod h1:kFF4jslnJ8pD5uCi17brj/ODlfIidOxlgUDTO5ncnC4=
|
||||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c h1:km8GpoQut05eY3GiYWEedbTT0qnSxrCjsVbb7yKY1KE=
|
||||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q=
|
||||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqdkI8FSpFyZDtCVBc2VmejdNrm5rRQ=
|
||||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
|
||||
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||
golang.org/x/image v0.44.0 h1:+tDekMZED9+LrtB3G5xzRggpVh9CARjZqROla3R3R+I=
|
||||
golang.org/x/image v0.44.0/go.mod h1:V8K3KE9KKKE+pLpQDOeN18w9oacNSvy1tDOirTu4xtY=
|
||||
golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE=
|
||||
golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU=
|
||||
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
|
||||
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/text v0.40.0 h1:Ub2Z6/xjgF1WrYQz2nuITOEegKFtiIy+rieRJ5lHZKs=
|
||||
golang.org/x/text v0.40.0/go.mod h1:hpnzDAfGV753zIKo+wk3u1bVKCGPbrnF7+7LBF/UHVY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
@@ -1,422 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
// CalendarWidget represents a custom calendar widget
|
||||
type CalendarWidget struct {
|
||||
widget.BaseWidget
|
||||
currentTime time.Time
|
||||
selectedTime time.Time
|
||||
onDateSelected func(time.Time)
|
||||
}
|
||||
|
||||
func NewCalendarWidget(initialTime time.Time, onDateSelected func(time.Time)) *CalendarWidget {
|
||||
c := &CalendarWidget{
|
||||
currentTime: initialTime,
|
||||
selectedTime: initialTime,
|
||||
onDateSelected: onDateSelected,
|
||||
}
|
||||
c.ExtendBaseWidget(c)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *CalendarWidget) CreateRenderer() fyne.WidgetRenderer {
|
||||
c.ExtendBaseWidget(c)
|
||||
return &calendarRenderer{
|
||||
calendar: c,
|
||||
objects: []fyne.CanvasObject{},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CalendarWidget) SetMonth(t time.Time) {
|
||||
c.currentTime = t
|
||||
c.Refresh()
|
||||
}
|
||||
|
||||
func (c *CalendarWidget) PreviousMonth() {
|
||||
c.currentTime = c.currentTime.AddDate(0, -1, 0)
|
||||
c.Refresh()
|
||||
}
|
||||
|
||||
func (c *CalendarWidget) NextMonth() {
|
||||
c.currentTime = c.currentTime.AddDate(0, 1, 0)
|
||||
c.Refresh()
|
||||
}
|
||||
|
||||
type calendarRenderer struct {
|
||||
calendar *CalendarWidget
|
||||
objects []fyne.CanvasObject
|
||||
}
|
||||
|
||||
func (r *calendarRenderer) Layout(size fyne.Size) {
|
||||
// Layout is handled by the container
|
||||
}
|
||||
|
||||
func (r *calendarRenderer) MinSize() fyne.Size {
|
||||
return fyne.NewSize(350, 300)
|
||||
}
|
||||
|
||||
func (r *calendarRenderer) Refresh() {
|
||||
r.calendar.BaseWidget.Refresh()
|
||||
}
|
||||
|
||||
func (r *calendarRenderer) Objects() []fyne.CanvasObject {
|
||||
return r.objects
|
||||
}
|
||||
|
||||
func (r *calendarRenderer) Destroy() {}
|
||||
|
||||
// CreateTimePicker creates a shadcn-style time picker
|
||||
func CreateTimePicker(currentTime time.Time, onTimeSelected func(time.Time)) fyne.CanvasObject {
|
||||
// Use pointers to allow modification in closures
|
||||
hours := currentTime.Hour()
|
||||
minutes := currentTime.Minute()
|
||||
seconds := currentTime.Second()
|
||||
|
||||
// Define updateTime before the select widgets
|
||||
updateTime := func() {
|
||||
selectedTime := time.Date(
|
||||
currentTime.Year(),
|
||||
currentTime.Month(),
|
||||
currentTime.Day(),
|
||||
hours,
|
||||
minutes,
|
||||
seconds,
|
||||
0,
|
||||
time.Local,
|
||||
)
|
||||
onTimeSelected(selectedTime)
|
||||
}
|
||||
|
||||
// Create select widgets
|
||||
hourSelect := widget.NewSelect(
|
||||
generateRange(0, 23),
|
||||
func(value string) {
|
||||
if value != "" {
|
||||
var hour int
|
||||
fmt.Sscanf(value, "%d", &hour)
|
||||
hours = hour
|
||||
updateTime()
|
||||
}
|
||||
},
|
||||
)
|
||||
hourSelect.SetSelected(fmt.Sprintf("%02d", hours))
|
||||
|
||||
minuteSelect := widget.NewSelect(
|
||||
generateRange(0, 59),
|
||||
func(value string) {
|
||||
if value != "" {
|
||||
var minute int
|
||||
fmt.Sscanf(value, "%d", &minute)
|
||||
minutes = minute
|
||||
updateTime()
|
||||
}
|
||||
},
|
||||
)
|
||||
minuteSelect.SetSelected(fmt.Sprintf("%02d", minutes))
|
||||
|
||||
secondSelect := widget.NewSelect(
|
||||
generateRange(0, 59),
|
||||
func(value string) {
|
||||
if value != "" {
|
||||
var second int
|
||||
fmt.Sscanf(value, "%d", &second)
|
||||
seconds = second
|
||||
updateTime()
|
||||
}
|
||||
},
|
||||
)
|
||||
secondSelect.SetSelected(fmt.Sprintf("%02d", seconds))
|
||||
|
||||
// Time display with colons
|
||||
timeContainer := container.NewGridWithColumns(5,
|
||||
hourSelect,
|
||||
widget.NewLabel(":"),
|
||||
minuteSelect,
|
||||
widget.NewLabel(":"),
|
||||
secondSelect,
|
||||
)
|
||||
|
||||
return container.NewVBox(
|
||||
widget.NewLabel("Select Time:"),
|
||||
timeContainer,
|
||||
)
|
||||
}
|
||||
|
||||
func generateRange(min, max int) []string {
|
||||
result := make([]string, max-min+1)
|
||||
for i := range result {
|
||||
result[i] = fmt.Sprintf("%02d", min+i)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// CreateCalendarView creates a calendar view widget
|
||||
func CreateCalendarView(initialTime time.Time, onDateSelected func(time.Time)) fyne.CanvasObject {
|
||||
currentMonth := initialTime
|
||||
|
||||
// Month names
|
||||
months := []string{
|
||||
"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December",
|
||||
}
|
||||
|
||||
// Generate years (current year +/- 10)
|
||||
currentYear := time.Now().Year()
|
||||
years := make([]string, 21)
|
||||
for i := 0; i < 21; i++ {
|
||||
years[i] = fmt.Sprintf("%d", currentYear-10+i)
|
||||
}
|
||||
|
||||
// Calendar grid
|
||||
calendarGrid := container.NewGridWithColumns(7)
|
||||
|
||||
// Declare variables before creating updateCalendar
|
||||
var updateCalendar func()
|
||||
var prevBtn, nextBtn *widget.Button
|
||||
var monthSelect, yearSelect *widget.Select
|
||||
updatingCalendar := false // Flag to prevent recursive updates
|
||||
|
||||
// Define updateCalendar
|
||||
updateCalendar = func() {
|
||||
if updatingCalendar {
|
||||
return
|
||||
}
|
||||
updatingCalendar = true
|
||||
defer func() { updatingCalendar = false }()
|
||||
|
||||
// Update dropdowns to match current month (only if they exist)
|
||||
if monthSelect != nil {
|
||||
monthSelect.SetSelected(currentMonth.Format("January"))
|
||||
}
|
||||
if yearSelect != nil {
|
||||
yearSelect.SetSelected(fmt.Sprintf("%d", currentMonth.Year()))
|
||||
}
|
||||
|
||||
// Clear grid
|
||||
calendarGrid.Objects = nil
|
||||
|
||||
// Add day headers
|
||||
days := []string{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
|
||||
for _, day := range days {
|
||||
dayLabel := widget.NewLabel(day)
|
||||
dayLabel.Alignment = fyne.TextAlignCenter
|
||||
dayLabel.TextStyle = fyne.TextStyle{Bold: true}
|
||||
calendarGrid.Add(dayLabel)
|
||||
}
|
||||
|
||||
// Get first day of month and number of days
|
||||
firstOfMonth := time.Date(currentMonth.Year(), currentMonth.Month(), 1, 0, 0, 0, 0, time.Local)
|
||||
lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
|
||||
firstDayWeekday := int(firstOfMonth.Weekday())
|
||||
daysInMonth := lastOfMonth.Day()
|
||||
|
||||
// Calculate days from previous month to fill first week
|
||||
daysFromPrevMonth := firstDayWeekday
|
||||
prevMonthTime := firstOfMonth.AddDate(0, -1, 0)
|
||||
// Get the last day of previous month
|
||||
lastDayOfPrevMonth := time.Date(prevMonthTime.Year(), prevMonthTime.Month(), 1, 0, 0, 0, 0, time.Local).AddDate(0, 1, -1).Day()
|
||||
|
||||
// Add days from previous month (starting from the appropriate day)
|
||||
startDay := lastDayOfPrevMonth - daysFromPrevMonth + 1
|
||||
for day := startDay; day <= lastDayOfPrevMonth; day++ {
|
||||
dayTime := time.Date(prevMonthTime.Year(), prevMonthTime.Month(), day, 0, 0, 0, 0, time.Local)
|
||||
|
||||
dayBtn := widget.NewButton(fmt.Sprintf("%d", day), nil)
|
||||
dayBtn.Importance = widget.LowImportance
|
||||
|
||||
dayBtn.OnTapped = func() {
|
||||
onDateSelected(dayTime)
|
||||
currentMonth = dayTime
|
||||
updateCalendar()
|
||||
}
|
||||
|
||||
calendarGrid.Add(dayBtn)
|
||||
}
|
||||
|
||||
// Add days from current month
|
||||
today := time.Now()
|
||||
for day := 1; day <= daysInMonth; day++ {
|
||||
dayTime := time.Date(currentMonth.Year(), currentMonth.Month(), day, 0, 0, 0, 0, time.Local)
|
||||
isToday := dayTime.Year() == today.Year() &&
|
||||
dayTime.Month() == today.Month() &&
|
||||
dayTime.Day() == today.Day()
|
||||
|
||||
dayBtn := widget.NewButton(fmt.Sprintf("%d", day), nil)
|
||||
|
||||
if isToday {
|
||||
dayBtn.Importance = widget.HighImportance
|
||||
}
|
||||
|
||||
dayBtn.OnTapped = func() {
|
||||
onDateSelected(dayTime)
|
||||
}
|
||||
|
||||
calendarGrid.Add(dayBtn)
|
||||
}
|
||||
|
||||
// Calculate total cells and add days from next month
|
||||
totalCells := daysFromPrevMonth + daysInMonth
|
||||
remainingCells := (7 - (totalCells % 7)) % 7
|
||||
if remainingCells == 0 && totalCells < 42 {
|
||||
remainingCells = 7
|
||||
}
|
||||
|
||||
// Fill to complete 6 weeks (42 cells)
|
||||
if totalCells+remainingCells < 42 {
|
||||
remainingCells = 42 - totalCells
|
||||
}
|
||||
|
||||
nextMonthTime := firstOfMonth.AddDate(0, 1, 0)
|
||||
for day := 1; day <= remainingCells; day++ {
|
||||
dayTime := time.Date(nextMonthTime.Year(), nextMonthTime.Month(), day, 0, 0, 0, 0, time.Local)
|
||||
|
||||
dayBtn := widget.NewButton(fmt.Sprintf("%d", day), nil)
|
||||
dayBtn.Importance = widget.LowImportance
|
||||
|
||||
dayBtn.OnTapped = func() {
|
||||
onDateSelected(dayTime)
|
||||
currentMonth = dayTime
|
||||
updateCalendar()
|
||||
}
|
||||
|
||||
calendarGrid.Add(dayBtn)
|
||||
}
|
||||
|
||||
calendarGrid.Refresh()
|
||||
}
|
||||
|
||||
// Month dropdown
|
||||
monthSelect = widget.NewSelect(months, func(value string) {
|
||||
if value != "" {
|
||||
for i, month := range months {
|
||||
if month == value {
|
||||
newMonth := time.Date(currentMonth.Year(), time.Month(i+1), 1, 0, 0, 0, 0, time.Local)
|
||||
currentMonth = newMonth
|
||||
updateCalendar()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
monthSelect.SetSelected(currentMonth.Format("January"))
|
||||
|
||||
// Year dropdown
|
||||
yearSelect = widget.NewSelect(years, func(value string) {
|
||||
if value != "" {
|
||||
year, _ := strconv.Atoi(value)
|
||||
newMonth := time.Date(year, currentMonth.Month(), 1, 0, 0, 0, 0, time.Local)
|
||||
currentMonth = newMonth
|
||||
updateCalendar()
|
||||
}
|
||||
})
|
||||
yearSelect.SetSelected(fmt.Sprintf("%d", currentMonth.Year()))
|
||||
|
||||
// Navigation buttons
|
||||
prevBtn = widget.NewButton("<", func() {
|
||||
currentMonth = currentMonth.AddDate(0, -1, 0)
|
||||
updateCalendar()
|
||||
})
|
||||
|
||||
nextBtn = widget.NewButton(">", func() {
|
||||
currentMonth = currentMonth.AddDate(0, 1, 0)
|
||||
updateCalendar()
|
||||
})
|
||||
|
||||
// Initial calendar update
|
||||
updateCalendar()
|
||||
|
||||
// Navigation header with dropdowns
|
||||
monthYearRow := container.NewBorder(nil, nil, prevBtn, nextBtn,
|
||||
container.NewGridWithColumns(2, monthSelect, yearSelect),
|
||||
)
|
||||
|
||||
// Combine everything
|
||||
calendarContainer := container.NewVBox(
|
||||
monthYearRow,
|
||||
widget.NewSeparator(),
|
||||
calendarGrid,
|
||||
)
|
||||
|
||||
return calendarContainer
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := app.New()
|
||||
w := a.NewWindow("Time Changer")
|
||||
w.Resize(fyne.NewSize(500, 600))
|
||||
|
||||
// Get current time
|
||||
currentTime := time.Now()
|
||||
|
||||
// Selected date label
|
||||
selectedDateLabel := widget.NewLabel("Selected Date:")
|
||||
selectedDateLabel.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
selectedDateValue := widget.NewLabel(currentTime.Format("2006-01-02"))
|
||||
|
||||
// Display label for selected datetime
|
||||
selectedDateTimeLabel := widget.NewLabel(fmt.Sprintf(
|
||||
"%04d-%02d-%02d %02d:%02d:%02d",
|
||||
currentTime.Year(), currentTime.Month(), currentTime.Day(),
|
||||
currentTime.Hour(), currentTime.Minute(), currentTime.Second(),
|
||||
))
|
||||
selectedDateTimeLabel.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
// Update preview function (must be defined before it's used)
|
||||
updatePreview := func() {
|
||||
date, _ := time.Parse("2006-01-02", selectedDateValue.Text)
|
||||
selectedDateTimeLabel.SetText(fmt.Sprintf(
|
||||
"%04d-%02d-%02d %02d:%02d:%02d",
|
||||
date.Year(), date.Month(), date.Day(),
|
||||
currentTime.Hour(), currentTime.Minute(), currentTime.Second(),
|
||||
))
|
||||
}
|
||||
|
||||
// Calendar with date selection callback
|
||||
calendar := CreateCalendarView(currentTime, func(selectedDate time.Time) {
|
||||
selectedDateValue.SetText(selectedDate.Format("2006-01-02"))
|
||||
currentTime = selectedDate
|
||||
updatePreview()
|
||||
})
|
||||
|
||||
// Time picker with callback
|
||||
timePicker := CreateTimePicker(currentTime, func(selectedTime time.Time) {
|
||||
currentTime = selectedTime
|
||||
updatePreview()
|
||||
})
|
||||
|
||||
// Set current time button
|
||||
setCurrentButton := widget.NewButton("Set to Current Time", func() {
|
||||
now := time.Now()
|
||||
currentTime = now
|
||||
selectedDateValue.SetText(now.Format("2006-01-02"))
|
||||
updatePreview()
|
||||
})
|
||||
|
||||
// Layout
|
||||
content := container.NewVBox(
|
||||
selectedDateLabel,
|
||||
calendar,
|
||||
selectedDateValue,
|
||||
widget.NewSeparator(),
|
||||
timePicker,
|
||||
widget.NewSeparator(),
|
||||
setCurrentButton,
|
||||
widget.NewSeparator(),
|
||||
widget.NewLabel("Preview:"),
|
||||
selectedDateTimeLabel,
|
||||
)
|
||||
|
||||
w.SetContent(content)
|
||||
w.ShowAndRun()
|
||||
}
|
||||
Reference in new issue
Block a user