dayjs OpenHarmony Adaptation Proposal
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
### Background
OpenHarmony is an open-source project incubated and operated by the OpenAtom Foundation. Its goal is to build an operating system framework and platform for intelligent terminal devices in the era of full scenarios, full connectivity, and full intelligence.
OpenHarmony uses JavaScript to develop native desktop applications, especially suitable for building lightweight, cross-device application interfaces and interaction logic. The "develop once, run on multiple platforms" feature is expected to attract more JavaScript developers, driving explosive growth in lightweight IoT applications. For teams familiar with front-end technologies, OpenHarmony + JavaScript is undoubtedly an efficient path to enter the full-scenario intelligent ecosystem.
**dayjs** is a lightweight yet powerful JavaScript date and time processing library, focusing on concise API design and high-performance operations. As a modern alternative to Moment.js, it perfectly supports chaining calls, internationalization, timezone handling, and plugin extensions, while being only a few KB in size, making it ideal for resource-sensitive scenarios. This characteristic aligns highly with OpenHarmony's requirements for lightweight and high-performance operations across multiple terminal devices (such as smartwatches, IoT devices, foldable smartphones, etc.). Currently, **dayjs** is gradually gaining popularity in OpenHarmony cross-platform application development, especially in scenarios requiring efficient time formatting, multi-timezone conversion, and date calculations. We believe that combining OpenHarmony's distributed capabilities with dayjs's flexible extensibility can further promote its deep integration in fields like smart homes and industrial IoT, providing developers with a simpler and more unified cross-device time management solution.
We will submit the adaptation code via a pull request (PR) as soon as possible. Creating this issue aims to foster in-depth discussions with the community regarding the integration of the adaptation code. We sincerely welcome your valuable suggestions.
In our first PR, we plan to add installation instructions for the OpenHarmony development environment to the project README, along with hyperlinks pointing to OpenHarmony development examples, hoping to attract more front-end developers to notice the OpenHarmony system. In subsequent usage by OpenHarmony community developers, if defects are found or general new requirements are identified, we will actively provide feedback and contribute to the dayjs project.
We will also continue to participate in the **dayjs** community and provide technical support for using **dayjs** on OpenHarmony.
### Adaptation Plan
We have completed the adaptation of dayjs for OpenHarmony, with the following details:
- Provided a [demo](https://gitcode.com/openharmony-tpc/openharmony_tpc_samples/tree/master/dayjs) for using dayjs in HarmonyOS.
- Following the OHPM (OpenHarmony Package Manager) specification, the adapted version has been published to the OpenHarmony [Third-Party Software Package Center](https://ohpm.openharmony.cn/#/cn/detail/dayjs).
These adaptation measures retain all of dayjs's original functionality while further enhancing its unique value within the OpenHarmony ecosystem.
### Test Results
We conducted unit tests on dayjs using the original test cases based on the OpenHarmony system.
The following versions have been verified:
- DevEco Studio: NEXT Beta1-5.0.3.806, SDK: API12 Release(5.0.0.66)
- DevEco Studio: 4.0(4.0.3.512), SDK: API10(4.0.10.9)
- DevEco Studio: 3.2Release(3.1.3.400), OpenHarmony SDK: API9 Release(3.2.11.5).
- DevEco Studio: 4.1 Release (4.1.0.400), SDK: API 11 Release (4.1.7.5).
Unit test case coverage is as follows:
| Interface Name | Passed | Notes |
| ---------------------------------------- | ------ | ----- |
| clone() | pass | |
| isValid() | pass | |
| year() | pass | |
| year(value:number) | pass | |
| month() | pass | |
| month(value:number) | pass | |
| date() | pass | |
| date(value:number) | pass | |
| day() | pass | |
| day(value:number) | pass | |
| hour() | pass | |
| hour(value:number) | pass | |
| minute() | pass | |
| minute(value:number) | pass | |
| second() | pass | |
| second(value:number) | pass | |
| millisecond() | pass | |
| millisecond(value:number) | pass | |
| set(unit:UnitType,value:number) | pass | |
| get(unit:UnitType) | pass | |
| add(value:number,unit?:ManipulateType) | pass | |
| subtract(value:number,unit?:ManipulateType) | pass | |
| startOf(unit:OpUnitType) | pass | |
| endOf(unit:OpUnitType) | pass | |
| format(template?:string) | pass | |
| diff(date?:ConfigType,unit?:QUnitType\|OpUnitType,float?:boolean) | pass | |
| valueOf() | pass | |
| unix() | pass | |
| daysInMonth() | pass | |
| toDate() | pass | |
| toJSON() | pass | |
| toISOString() | pass | |
| toString() | pass | |
| utcOffset() | pass | |
| isBefore(date:ConfigType,unit?:OpUnitType) | pass | |
| isSame(date:ConfigType,unit?:OpUnitType) | pass | |
| isAfter(date:ConfigType,unit?:OpUnitType) | pass | |
| locale() | pass | |
If needed, we can provide a detailed test report at any time.
### Benefits to the Upstream Community
- Reach OpenHarmony's vast user base and developer community.
- Ensure long-term development potential by supporting cutting-edge operating system trends.
- Enhance the project's ability to handle diverse runtime environments.
### Tags
Enhancement, Compatibility, Cross-Platform
Contributor guide
Assessment
This issue has not been assessed yet.