gpnalin/module-date-time 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gpnalin/module-date-time

Composer 安装命令:

composer require gpnalin/module-date-time

包简介

N/A

README 文档

README

Overview

The Aligent DateTime API is a Magento 2 module that provides functionality to calculate the difference between two dates. It supports various calculation types and can be accessed via both REST API and GraphQL.

Features

  • Calculate the difference between two dates in:
    • days: Calculate the total number of days
    • weekdays: Calculate the number of weekdays (Monday to Friday)
    • weeks: Calculate the number of complete weeks
    • hours: Calculate the total number of hours
    • minutes: Calculate the total number of minutes
    • seconds: Calculate the total number of seconds
    • years: Calculate the number of years
  • Support for standard datetime formats with timezone
  • REST API endpoint
  • GraphQL query
  • Unit test and API/GraphQL functional testing

Installation

  1. If you already have Magento instance setup, skip to #6.
  2. Create your project directory then go into it:
    mkdir magento.test; cd $_;
    
  3. Download the Docker Compose template:
    curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash
    
  4. Download the version of Magento you want to use with:
    bin/download 2.4.7 community
    
  5. Run the setup installer for Magento:
    bin/setup magento.test
    
  6. Install the module:
    bin/composer require gpnalin/module-date-time
    
    # or clone the module to app/code/Aligent/DateTime
    
    mkdir -p app/code/Aligent;
    cd $_;
    git clone git@github.com:gpnalin/module-date-time.git DateTime;
    
  7. Enable the module by running:
    bin/magento module:enable Aligent_DateTime
    
  8. Run the Magento setup upgrade:
    bin/magento setup:upgrade
    
  9. Compile Dependency Injection:
    bin/magento setup:di:compile
    
  10. Clean the cache:
bin/magento cache:clean

Usage

REST API

Endpoint

POST /V1/datetime/calculate

Parameters

  • startDate (string): The start date in ISO 8601 format (e.g., "2023-01-01T00:00:00+00:00")
  • endDate (string): The end date in ISO 8601 format (e.g., "2023-01-10T00:00:00+00:00")
  • calculationType (string): The type of calculation to perform (days, weekdays, weeks, hours, minutes, seconds, years)

Example Request

POST /V1/datetime/calculate
Content-Type: application/json

{
  "startDate": "2023-01-01T00:00:00+00:00",
  "endDate": "2023-01-10T00:00:00+00:00",
  "calculationType": "days"
}

Example Response

{
    "result": 9
}

GraphQL

Query

query DiffCalculatorQuery(
  $startDate: String!,
  $endDate: String!,
  $calculationType: CalculationType!
) {
    DiffCalculatorQuery(
    startDate: $startDate,
    endDate: $endDate,
    calculationType: $calculationType
  ) {
    result
  }
}

Variables

{
  "startDate": "2023-01-01T00:00:00+00:00",
  "endDate": "2023-01-10T00:00:00+00:00",
  "calculationType": "days"
}

Example Response

{
  "data": {
    "DiffCalculatorQuery": {
      "result": 9
    }
  }
}

Error Handling

Both the REST API and GraphQL query will return appropriate error messages if the input is invalid or if an unexpected error occurs during calculation.

Notes

  • All dates should be provided in standard datetime formats with timezone information.
  • If no timezone is specified, UTC is assumed.
  • The endDate must be greater than or equal to the startDate.

Test Coverage

  • Unit Test
    /usr/local/bin/php -dmemory_limit=-1 $(pwd)/vendor/bin/phpunit --bootstrap $(pwd)/dev/tests/unit/framework/bootstrap.php --configuration $(pwd)/dev/tests/unit/phpunit.xml.dist $(pwd)/vendor/gpnalin/module-date-time/Test/Unit/
    
  • Web API Functional Test
    /usr/local/bin/php -dmemory_limit=-1 $(pwd)/vendor/bin/phpunit -c $(pwd)/dev/tests/api-functional/phpunit_rest.xml.dist $(pwd)/vendor/gpnalin/module-date-time/Test/Api/
    
  • GraphQL Functional Test
    /usr/local/bin/php -dmemory_limit=-1 $(pwd)/vendor/bin/phpunit -c $(pwd)/dev/tests/api-functional/phpunit_graphql.xml.dist $(pwd)/vendor/gpnalin/module-date-time/Test/GraphQl/
    

gpnalin/module-date-time 适用场景与选型建议

gpnalin/module-date-time 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 gpnalin/module-date-time 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gpnalin/module-date-time 我们能提供哪些服务?
定制开发 / 二次开发

基于 gpnalin/module-date-time 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: OSL-3.0
  • 更新时间: 2024-08-25