Time error processing method and terminal in 32-bit system

By configuring the earliest time point and calculating offset values ​​in a 32-bit system, the time error problem caused by time_t data type limitation is solved, and the accurate access and flexible settings of time data are achieved, reducing the development workload and compatibility risks.

CN119668359APending Publication Date: 2025-03-21FUJIAN WISBO DIGITAL TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411937947.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-03-21

AI Technical Summary

Technical Problem

Due to the limitation of time_t data type in 32-bit systems, a time error will occur after January 19, 2038, resulting in serious problems with the program. Existing solutions such as replacing them with 64-bit operating systems or extended time_t data types have problems such as high hardware configuration requirements, high development workload and compatibility risks.

Method used

By configuring the earliest time point that is allowed to be set by the system, and calculating the offset value between the time point and the default starting time point, the offset value is used to access time data, thereby breaking through the limitation of the time storage range in the 32-bit system.

Benefits of technology

It realizes that the second-level time is accurately recorded without changing the original code, and the changes to the original system are small, avoiding the problem of time overflow, and reducing the development workload and compatibility risks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119668359A_ABST
    Figure CN119668359A_ABST
Patent Text Reader

Abstract

The invention provides a time error processing method in a 32-bit system and a terminal. The method comprises the following steps: acquiring a default starting time point in the system; configuring an earliest time point allowing system setting; calculating a deviation value between the earliest time point and the default starting time point; and accessing the time data according to the deviation value. According to the method, more flexible time setting is realized in a mode of adjusting the time data by adding the offset value, the data type of the original storage time is reserved, and only the offset value considering the record needs to be added in an original mode of processing the time data without changing an original code, so that the time setting efficiency is improved. The second-level time can be accurately recorded, and the change of the original system is small.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer systems, and in particular to a time error processing method and a terminal in a 32-bit system. Background Art

[0002] In the interrupt of running 32-bit system, the operating system usually calculates Greenwich time by taking 00:00:00 on January 1, 1970 as the base time and adding the total number of seconds of running. The data type of the variable that saves the total number of seconds of running is time_t. This data type is a 4-byte signed long integer in 32-bit operating system. After conversion to decimal, the value range is: -2147483648 to 2147483647. Therefore, the last time that can be represented is the 2147483647th second (representing 03:14:07 am on January 19, 2038 Greenwich time). The next second will overflow into a negative number and become -2147483648th second (representing 20:45:52 on December 13, 1901 Greenwich time), causing serious time errors in the program.

[0003] There are two main ways to solve this time error. One way is to directly update the operating system to a 64-bit operating system. Then the time_t data type is automatically compiled as 8 bytes of a long integer. The value range after conversion to decimal is: -9223372036854775808 to 9223372036854775807. The maximum number of seconds that can be expressed will change from 2147483647 seconds to 9223372036854775807. The last time expressed is 15:30:08 on December 4, 292,277,026,596, 290 billion years later. This method is enough to meet the time required by the system. However, the chip architecture of some products does not support the operation of 64-bit operating systems, and the memory hardware resource configuration of some products is low and cannot support the operation of 64-bit operating systems. After switching the operating system to 64-bit, some applications need to be redeveloped and compiled. Therefore, this solution has high requirements on the hardware configuration of the device, is not universal, and requires a lot of development work.

[0004] Another way is to expand the time_t data type from 4 bytes of long integer to 8 bytes of long integer in a 32-bit operating system, and modify all program codes involving the time_t data type. Since the data width of time_t has been modified, all codes involving this data type need to be adjusted, resulting in a huge amount of changes in the entire operating system that has been completed. In some external call libraries, since there is no source code available for modification, changes in the data structure of the parameters can easily cause incompatible crashes. Therefore, the development workload of this solution is huge, and there is a high compatibility risk. Summary of the invention

[0005] The technical problem to be solved by the present invention is to provide a time error processing method and terminal in a 32-bit system, so as to realize a time processing method in a 32-bit system with little modification and accurate calculation.

[0006] In order to solve the above technical problems, a technical solution adopted by the present invention is: A method for handling time errors in a 32-bit system, comprising the steps of: Get the default starting time point in the system; The earliest point in time that the configuration allows the system to be set up; Calculating an offset value between the earliest time point and the default starting time point; The time data is accessed according to the offset value.

[0007] In order to solve the above technical problems, another technical solution adopted by the present invention is: A time error processing terminal in a 32-bit system comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program: Get the default starting time point in the system; The earliest point in time that the configuration allows the system to be set up; Calculating an offset value between the earliest time point and the default starting time point; The time data is accessed according to the offset value.

[0008] The beneficial effects of the present invention are as follows: the earliest time point that the system is allowed to adjust is configured, an offset value is calculated from a default starting time point in the system, a portion exceeding the storable length in a 32-bit system is stored through the offset value, and access to time data is achieved in the system by coordinating the offset value with the original data type for storing time, thereby being able to break through the limitation on the time storage range in the original system; and more flexible time settings are achieved by adjusting the time data by adding an offset value, retaining the original data type for storing time, and only the offset value for recording needs to be added to the original method of processing time data, without changing the original code, and being able to accurately record time at the second level with minimal changes to the original system. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] Figure 1 A flowchart of a method for handling time errors in a 32-bit system according to an embodiment of the present invention; Figure 2 It is an implementation architecture diagram of a time error processing method in a 32-bit system according to an embodiment of the present invention; Figure 3 A schematic diagram of the structure of a time error processing terminal in a 32-bit system according to an embodiment of the present invention; Description of labels: 1. A time error handling terminal in a 32-bit system; 2. A processor; 3. A memory. DETAILED DESCRIPTION

[0010] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.

[0011] Please refer to Figure 1 , a time error handling method in a 32-bit system, characterized in that it comprises the steps of: Get the default starting time point in the system; The earliest point in time that the configuration allows the system to be set up; Calculating an offset value between the earliest time point and the default starting time point; The time data is accessed according to the offset value.

[0012] From the above description, it can be seen that the beneficial effects of the present invention are: the earliest time point that the configuration allows the system to adjust is calculated, the offset value is calculated from the default starting time point in the system, the part that exceeds the storable length in the 32-bit system is stored through the offset value, and the system accesses the time data by coordinating the offset value with the original data type for storing time, thereby breaking through the limitation on the time storage range in the original system; and a more flexible time setting is achieved by adding an offset value to adjust the time data, retaining the original data type for storing time, and only needs to add the offset value for recording to the original way of processing time data, without changing the original code, and can accurately record the time in seconds with little change to the original system.

[0013] Furthermore, it also includes: Get the maximum time interval that can be represented by the length of the data type used to store time in the system; The configuration allows the system to set the latest time point, and the difference between the earliest time point and the latest time point does not exceed the maximum time interval; The accessing of time data according to the offset value comprises: Receiving first time data set by an application between the earliest time point and the latest time point; The first time data is subtracted from the offset value and then saved.

[0014] From the above description, it can be seen that when configuring the earliest time point, the latest time point is also configured, so that when time setting is required, the time range allowed for setting can be quickly obtained, and there is no need to calculate the allowed range separately when setting the time, and the difference between the earliest time point and the latest time point allowed for system setting is limited to be less than or equal to the maximum time interval, thereby ensuring that on the basis of the offset determination, the complete time range can be represented by the length of the original data type used to store time in the system, and when saving data, the first time data received is subtracted from the offset value for saving. Since it is ensured that the time range allowed for setting is within the maximum time interval, it can be ensured that the value after subtracting the offset value is within the maximum time interval, and the problem of data overflow in the data type is avoided by coordinating the offset value with the native data type for storing time.

[0015] Further, accessing the time data according to the offset value includes: receiving a time reading request from an application, and acquiring the stored second time data; The second time data is added with the offset value and then returned to the application.

[0016] From the above description, it can be seen that since the second time data stored in the system is based on the acquired time minus the offset value, after acquiring the time in the system at this time, the offset value needs to be added to obtain the real time data, and the data after adding the offset value is returned to the application, that is, the application can obtain the real time, and in the process of storing time in the system, the possible overflow part is represented by the offset value, thus avoiding the problem of overflow of the data type of the stored time.

[0017] Further, accessing the time data according to the offset value also includes: Acquire network time, and determine the time difference between the network time and the earliest time point; If the time difference is greater than a first preset value, the earliest time point is updated backward by a second preset value to obtain an updated earliest time point; The step of calculating the offset value between the earliest time point and the default start time is performed again according to the updated earliest time point.

[0018] From the above description, it can be seen that when the network time is obtained through the Internet, if it is found that the time difference between the network time and the earliest time point is greater than the first preset value, the earliest time point will be updated backward by the second preset value. In this way, after setting the time range once, the system can automatically adjust according to the time obtained through the Internet, so as to automatically adjust the range before the newly set time range overflows again, thereby ensuring the normal display of time data.

[0019] Furthermore, the first preset value and the second preset value are smaller than the offset value.

[0020] From the above description, it can be seen that the first preset value and the second preset value are set to be smaller than the offset value, so that the time range can be postponed before the overflow occurs, and it is ensured that the time range after the postponement retains an overlapping part with the time range before the postponement, avoiding the problem of being unable to represent for a period of time after the postponed time range.

[0021] A time error processing terminal in a 32-bit system comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program: Get the default starting time point in the system; The earliest point in time that the configuration allows the system to be set up; Calculating an offset value between the earliest time point and the default starting time point; The time data is accessed according to the offset value.

[0022] The beneficial effects of the present invention are as follows: the earliest time point that the system is allowed to adjust is configured, an offset value is calculated from a default starting time point in the system, a portion exceeding the storable length in a 32-bit system is stored through the offset value, and access to time data is achieved in the system by coordinating the offset value with the original data type for storing time, thereby being able to break through the limitation on the time storage range in the original system; and more flexible time settings are achieved by adjusting the time data by adding an offset value, retaining the original data type for storing time, and only the offset value for recording needs to be added to the original method of processing time data, without changing the original code, and being able to accurately record time at the second level with minimal changes to the original system.

[0023] Furthermore, it also includes: Get the maximum time interval that can be represented by the length of the data type used to store time in the system; The configuration allows the system to set the latest time point, and the difference between the earliest time point and the latest time point does not exceed the maximum time interval; The accessing of time data according to the offset value comprises: Receiving first time data set by an application between the earliest time point and the latest time point; The first time data is subtracted from the offset value and then saved.

[0024] From the above description, it can be seen that when configuring the earliest time point, the latest time point is also configured, so that when time setting is required, the time range allowed for setting can be quickly obtained, and there is no need to calculate the allowed range separately when setting the time, and the difference between the earliest time point and the latest time point allowed for system setting is limited to be less than or equal to the maximum time interval, thereby ensuring that on the basis of the offset determination, the complete time range can be represented by the length of the original data type used to store time in the system, and when saving data, the first time data received is subtracted from the offset value for saving. Since it is ensured that the time range allowed for setting is within the maximum time interval, it can be ensured that the value after subtracting the offset value is within the maximum time interval, and the problem of data overflow in the data type is avoided by coordinating the offset value with the native data type for storing time.

[0025] Further, accessing the time data according to the offset value includes: receiving a time reading request from an application, and acquiring the stored second time data; The second time data is added with the offset value and then returned to the application.

[0026] From the above description, it can be seen that since the second time data stored in the system is based on the acquired time minus the offset value, after acquiring the time in the system at this time, the offset value needs to be added to obtain the real time data, and the data after adding the offset value is returned to the application, that is, the application can obtain the real time, and in the process of storing time in the system, the possible overflow part is represented by the offset value, thus avoiding the problem of overflow of the data type of the stored time.

[0027] Further, accessing the time data according to the offset value also includes: Acquire network time, and determine the time difference between the network time and the earliest time point; If the time difference is greater than a first preset value, the earliest time point is updated backward by a second preset value to obtain an updated earliest time point; The step of calculating the offset value between the earliest time point and the default start time is performed again according to the updated earliest time point.

[0028] From the above description, it can be seen that the network time is obtained by connecting to the Internet. If it is found that the time difference between the network time and the earliest time point is greater than the first preset value, the earliest time point will be updated backward by the second preset value. In this way, after setting the time range once, the system can automatically adjust according to the time obtained by connecting to the Internet, so as to automatically adjust the range before the newly set time range overflows again, thereby ensuring the normal display of time data.

[0029] Furthermore, the first preset value and the second preset value are smaller than the offset value.

[0030] From the above description, it can be seen that the first preset value and the second preset value are set to be smaller than the offset value, so that the time range can be postponed before the overflow occurs, and it is ensured that the time range after the postponement retains an overlapping part with the time range before the postponement, avoiding the problem of being unable to represent for a period of time after the postponed time range.

[0031] In the application layer of the 32-bit Android or OpenHarmony intelligent operating system, the numerical value representing time uses 8 bytes, which has a wide range of values ​​and does not have the problem of time overflow. However, the basic library and kernel at the bottom of the 32-bit operating system will use the problematic time_t data type. The above-mentioned time error processing method and terminal in a 32-bit system of the present invention can be applied to various electronic devices or embedded devices using a 32-bit system, and a processing method compatible with the time error in 2038 is added. It is particularly suitable for situations where the degree of change to the system needs to be reduced. The following is an explanation through a specific implementation method.

[0032] Please refer to Figure 1 , Embodiment 1 of the present invention is: A method for handling time errors in a 32-bit system, comprising the steps of: S1. Obtain the default starting time point in the system. For example, in the existing 32-bit Android or OpenHarmony, the Greenwich Mean Time is calculated based on 00:00:00 on January 1, 1970 as the default starting time point.

[0033] S2. Configure the earliest time point that the system is allowed to set. For example, set Greenwich Mean Time January 1, 2000 00:00:00 as the earliest time point.

[0034] S3, calculating the offset value between the earliest time point and the default start time point. For example, if the offset value between the earliest time point 00:00:00 on January 1, 2000 and the default start time point 00:00:00 on January 1, 1970 is 946684800 seconds, then 946684800 will be used as the offset value. It can be seen that the earliest time point earlier than the default start time can also be set, and the offset value is recorded as a negative number.

[0035] S4. Access time data according to the offset value.

[0036] In one embodiment of the present application, S01-S02 are also included before S4.

[0037] S01. Obtain the maximum time interval that can be represented by the length of the data type used to store time in the system. For example, the length of the data type time_t commonly used to store time in the current 32-bit operating system is 8 bytes, and the maximum time interval that can be represented is 2147483647 seconds.

[0038] S02. Configure the latest time point that the system is allowed to set, and the difference between the earliest time point and the latest time point does not exceed the maximum time interval. For example, the latest time point is configured as 00:00:00 on January 1, 2060, and the time interval between it and the earliest time point is less than the maximum time interval (if it is the maximum time interval, the latest time point is in 2068).

[0039] In this way, the difference between the earliest time point and the latest time point is set within the maximum time interval. Since the offset value has recorded the difference between the earliest time point and the default start time point, the time range between the earliest time point and the latest time point can be represented by the length of the data type used to store time in the system. The offset value is increased to match the original data type for storing time in the system to achieve the representation of any time range. The terminal usually provides the function of automatically obtaining time through networking and freely modifying time, so the configurable time range can be directly displayed here.

[0040] Then S4 includes: S401-S402.

[0041] S401, receiving the first time data set by the application between the earliest time point and the latest time point. For example, the upper layer application sets 2147483648 seconds, which represents 03:14:08 am on January 19, 2038 Greenwich time. The first time data may be the first time data set by the application when setting the system time using the automatic time configuration function, or the first time data set by the application using the timer function, such as setting an alarm or a timer wake-up function in the system.

[0042] S402, subtracting the offset value from the first time data and saving the data. Since the offset value 946684800 has been set, when storing in the system, 2147483648 seconds will be subtracted from the offset value 946684800 to obtain 1200798848 seconds for saving. 1200798848 is less than the maximum value that the time_t data type can represent, i.e., 2147483647, thus avoiding the problem of data type length overflow when storing time data, and the data can be stored through the system's underlying time_t.

[0043] In one embodiment of the present application, S4 includes S411 - S412 .

[0044] S411, receiving a time reading request from an application, and obtaining the stored second time data. For example, when an application needs to read the system time for display, the time stored in time_t is 1200798848 seconds, which represents 03:14:08 AM, January 20, 2008, Greenwich time. S412, adding the offset value to the second time data and returning it to the application. Since the offset value is deducted when storing the time data, the offset value 946684800 seconds needs to be added back to obtain 2147483648 seconds, which represents 03:14:08 am on January 19, 2038 Greenwich time, so that the application can obtain accurate time data, and what is stored in the system is the offset and the data type time_t when storing the time data.

[0045] In one embodiment of the present application, S4 includes S421-S423.

[0046] S421, obtaining network time, and determining the time difference between the network time and the earliest time point. For example, the currently obtained network time is 2050, and the time difference between the set earliest time point 2000 is 50 years.

[0047] S422: If the time difference is greater than the first preset value, the earliest time point is updated backward by a second preset value to obtain the updated earliest time point. If 50 years is greater than the first preset value, the earliest time point 2000 is updated backward by a second preset value. For example, if 20 years is the second preset value, the earliest time point updated backward is 00:00:00 on January 1, 2020.

[0048] If the latest time point is configured at the same time, the latest time point is synchronously updated to the second preset value. For example, the latest time point is updated from 00:00:00 on January 1, 2060 to 00:00:00 on January 1, 2080. This achieves synchronous update of the configurable time range.

[0049] S423: Return to S3 according to the updated earliest time point, that is, recalculate the offset value 1577808000 between 00:00:00 on January 1, 2020 and 00:00:00 on January 1, 1970.

[0050] The first preset value and the second preset value are smaller than the offset value.

[0051] In one embodiment of the present application, referring to Figure 2The above-mentioned method for handling time errors in a 32-bit system keeps the system bottom layer and the application upper layer unchanged, and performs time conversion in the intermediate framework layer, so that the upper layer application can continue to maintain the original 64-bit system without modification, and the system bottom layer can directly store time data in the data type used to store time in the original way. The intermediate framework layer provided in this application converts the time data stored in the system bottom layer to obtain the real time through the configured earliest time point and offset value.

[0052] Please refer to Figure 2 , Embodiment 2 of the present invention is: A time error processing terminal 1 in a 32-bit system comprises a processor 2, a memory 3 and a computer program stored in the memory 3 and executable on the processor 2. When the processor 2 executes the computer program, each step in the first embodiment is implemented.

[0053] In summary, the present invention provides a time error handling method and terminal in a 32-bit system, which realizes the storage of time by adding an offset value in conjunction with the original data type for storing time in the system, thereby solving the problem of overflow after the difference between the stored time and the default start time in the system exceeds the length limit of the data type. Because there is no need to modify the original data type for storing time in the system, there is no need to change the code logic in the system and application in large quantities. Only the functions of setting time, reading time, and synchronizing time in the system framework layer after adding the offset value need to be modified, thereby reducing the workload of development. At the same time, there is no need to modify the original data type for storing time in the system, which is consistent with the data structure of the parameters of the old source-free call library, thereby reducing the risk of program compatibility crash and improving system stability. And by setting the time range and then calculating the offset value, not only can the time later than the overflow value 03:14:07 on January 19, 2038, be recorded, but also the time earlier than the default starting time point 00:00:00 on January 1, 1970 can be recorded. It can adapt to the time configuration requirements in different scenarios, and the time can be uniquely determined by combining the offset value and the data type used to store time in the system, which is highly flexible.

[0054] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for handling time errors in a 32-bit system, characterized in that: Includes steps: Get the default starting time point in the system; The earliest point in time that the configuration allows the system to be set up; Calculating an offset value between the earliest time point and the default starting time point; The time data is accessed according to the offset value.

2. The method for handling time errors in a 32-bit system according to claim 1, characterized in that: Also includes: Get the maximum time interval that can be represented by the length of the data type used to store time in the system; The configuration allows the system to set the latest time point, and the difference between the earliest time point and the latest time point does not exceed the maximum time interval; The accessing of time data according to the offset value comprises: receiving first time data set by an application between the earliest time point and the latest time point; The first time data is subtracted from the offset value and then saved.

3. A time error handling method in a 32-bit system according to claim 1 or 2, characterized in that: The accessing of time data according to the offset value comprises: receiving a time reading request from an application, and acquiring the stored second time data; The second time data is added with the offset value and then returned to the application.

4. The method for handling time errors in a 32-bit system according to claim 1, characterized in that: The accessing of time data according to the offset value further comprises: Acquire network time, and determine the time difference between the network time and the earliest time point; If the time difference is greater than a first preset value, the earliest time point is updated backward by a second preset value to obtain an updated earliest time point; The step of calculating the offset value between the earliest time point and the default start time is performed again according to the updated earliest time point.

5. The method for handling time errors in a 32-bit system according to claim 4, characterized in that: The first preset value and the second preset value are smaller than the offset value.

6. A time error processing terminal in a 32-bit system, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the following steps are implemented: Get the default starting time point in the system; The earliest point in time that the configuration allows the system to be set up; Calculating an offset value between the earliest time point and the default starting time point; The time data is accessed according to the offset value.

7. A time error processing terminal in a 32-bit system according to claim 6, characterized in that: Also includes: Get the maximum time interval that can be represented by the length of the data type used to store time in the system; The configuration allows the system to set the latest time point, and the difference between the earliest time point and the latest time point does not exceed the maximum time interval; The accessing of time data according to the offset value comprises: Receiving first time data set by an application between the earliest time point and the latest time point; The first time data is subtracted from the offset value and then saved.

8. A time error processing terminal in a 32-bit system according to claim 6 or 7, characterized in that: The accessing of time data according to the offset value comprises: receiving a time reading request from an application, and acquiring the stored second time data; The second time data is added with the offset value and then returned to the application.

9. A time error processing terminal in a 32-bit system according to claim 6, characterized in that: The accessing of time data according to the offset value further comprises: Acquire network time, and determine the time difference between the network time and the earliest time point; If the time difference is greater than a first preset value, the earliest time point is updated backward by a second preset value to obtain an updated earliest time point; The step of calculating the offset value between the earliest time point and the default start time is performed again according to the updated earliest time point.

10. A time error processing terminal in a 32-bit system according to claim 9, characterized in that: The first preset value and the second preset value are smaller than the offset value.