Date/Datetime ile ÇalışmaWorking With Date/Datetime
Bu bölüm, date handling/manipulation'ı kolaylaştırmak için date/datetime/time type'larını, ilgili configuration'ları, yapıları ve konseptleri tanıtmayı amaçlarThis section aims to introduce date/datetime/time types, related configurations, structures and concepts to ease date handling/manipulation
Date Data Type'larıDate Data Types
Diğer bazı programlama dillerinin aksine, TROIA'nın date, datetime, time variable'larını saklamak ve manipüle etmek için birden fazla data type'ı vardır. Önceki bölümlerden data type'ları biliyoruz, ama bu type'lar hakkındaki bilgimizi tazelemek için ilgili data type'larının listesi:In contrary to some other programming languages, TROIA has more than one data type to store and manipulate date, datetime, time variables. We know about data types from previous sessions, but to refresh our knowledge about this types here is the list of related data types:
DATE (Ex: 23.04.1920, default value:definition date)
DATETIME (Ex: 29.10.1923 16:30:30, default value:definition time)
TIME (Ex: 21:30)
TIMES (Ex: 21:30:13)Görüldüğü gibi, DATE ve DATETIME type arasındaki ana fark, saat, dakika ve saniyeden oluşan time kısmıdır. TIME ve TIMES data type'ları yalnızca time bilgisini saklamak için kullanılır. Aralarındaki ana fark saniye kısmıdır. TIMES data type'ı, 5.01.01 sürümlerinden sonra desteklenen nispeten yeni bir data type'ıdır (3.08.x sürümlerinde desteklenmez.)As it is obvious, main difference between DATE and DATETIME type is time part which consisted by hour, minute and second. TIME and TIMES data types are used for storing only time information. Their main difference is second part. TIMES data type is relatively a new data type that is supported after 5.01.01 releases (not supported on 3.08.x releases.)
Application'ınızın gereksinimlerine göre en primitive data type'ı kullanmalısınız. Bir DATETIME symbol'ünde date bilgisini ve time kısmı olarak 00:00:00'ı saklamak önerilmez.Due to your application’s requirements you must use the most primitive data type. It is not recommended that storing a date information in a DATETIME symbol and 00:00:00 as its time part.
Date Type'larında Type Conversion & CastingType Conversion & Casting on Date Types
TROIA'nın type casting operation'larını arka planda ele aldığını biliyoruz. Bu kural date ile ilgili data type'ları için de geçerlidir, bu yüzden date, datetime, time, times variable'ını decimal hariç herhangi bir başka type variable'a atamak veya herhangi bir variable'ı herhangi bir date data type'ına atamak mümkündür.We know that TROIA handles type casting operations in background. This rule is also valid for date related data types, so it is possible to assign date, datetime, time, times variable any other typed variable except decimal, or assign any variable to any date data type.
İşte dört casting operation'ı içeren basit bir code block:Here is a simple code block that contains four casting operation:
OBJECT:
STRING STRINGVAR3,
DATETIME DATETIMEVAR1,
DATE DATEVAR1,
DATETIME DATETIMEVAR2,
TIME TIMEVAR1;
STRINGVAR3 = '25.11.1984 13:00:00';
DATETIMEVAR1 = STRINGVAR3;
DATEVAR1 = DATETIMEVAR1;
DATETIMEVAR2 = DATEVAR1;
TIMEVAR1 = DATETIMEVAR1;Bu örnekte, ilki bir string'i bir datetime variable'a atamaktır. Bu operation bir tür parsing operation'ı içerir; parsing ve formatting date'leri ilerleyen bölümlerde detaylıca ele alacağız. İkincisi datetime'ı date'e atamaktır, bu operation'da yalnızca date kısmı target variable'a aktarılır. Üçüncüsü date'ten datetime'a, bu durumda sistem target symbol'ün time kısmı için 00:00:00 kullanır. Sonuncusu datetime'dan time'a, bu durumda source variable'ın yalnızca time kısmı target symbol'e aktarılır.In this example, first one is assigning a string to a datetime variable. This operation contains a kind of parsing operation we will discuss parsing and formatting dates in following sections in detail. Second one is assigning datetime to date, in this operation only date part is transferred to target variable. The third one is date to datetime, in this case system uses 00:00:00 for the time part of target symbol. The last one is from datetime to time, In this case only time part of source variable transferred to target symbol.
Date ile ilgili symbol'leri cast etmenin çok fazla olasılığı vardır, ana yaklaşımı anlamak için lütfen kendi kodlarınızı yazın. Ayrıca daha fazla bilgi için "Operators and Expressions" bölümünü incelemek de faydalıdır. Long ve date ile ilgili data type'ları arasındaki ilişkiye odaklanacağız.There are too many possibilities casting date related symbols, please write your own codes to understand the main approach. It is also useful to review “Operators and Expressions” section for more information. We will focus on relation between long and date related data types.
Arka planda, tüm date ile ilgili type'lar long olarak saklanır, bu yüzden date ile ilgili type'lar ile long/integer variable'ları arasında type conversion/casting operation'ları yapmak da mümkündür. Bir date symbol'ünün long değeri, 01.01.1970 00:00:00'dan başlayan milisaniye değeridir (aslında timezone sorunları nedeniyle biraz daha karmaşıktır). Bir date ile ilgili variable'ı bir long'a veya bir long variable'ı bir date ile ilgili variable'a atamak mümkün olsa da, TROIA'nın aynı operation'ları ele almak için MILLISECONDSTODATE() ve DATETOMILLISECONDS() system function'ları vardır. İşte long ve datetime data type'ı hakkında bir örnek, daha iyi anlamak için lütfen sonuçları tartışın:In background, all date related types are stored as long, so it is also possible to make type conversion/casting operations between date related types and long/integer variables. Long value of a date symbol is millisecond value starts from 01.01.1970 00:00:00 (actually it is a little bit more complicated because of timezone issues). Although it is possible to assign a date related variable to a long or long variable to a date related variable is possible, TROIA has MILLISECONDSTODATE() and DATETOMILLISECONDS() system functions to handle same operations. Here is an example about long and datetime data type, please discuss the results for better understanding:
OBJECT:
STRING STRINGVAR3,
DATETIME DATETIMEVAR1,
DATETIME DATETIMEVAR2,
DATETIME DATETIMEVAR3,
LONG LONGVAR1,
LONG LONGVAR2;
DATETIMEVAR1 = '25.11.1984 13:00:00';
LONGVAR1 = DATETOMILLISECONDS(DATETIMEVAR1);
LONGVAR2 = DATETIMEVAR1;
DATETIMEVAR2 = MILLISECONDSTODATE(LONGVAR1);
DATETIMEVAR3 = MILLISECONDSTODATE(LONGVAR1);
STRINGVAR3 = LONGVAR1 + TOCHAR(10) + LONGVAR2;Bazı Faydalı Function'lar ve Variable'larSome Useful Functions and Variables
Güncel Date'i AlmaGetting Current Date
Date ile ilgili bir variable'ın initial değeri, initialize edildiği/oluşturulduğu zamandır, bu yüzden sadece bir date veya datetime variable'ı oluşturarak güncel date'i okumak mümkündür. Ama bu yaklaşımla güncel date almak, date ile ilgili bug'lar hakkında bir vulnerability oluşturur, bu yüzden bu seçeneği kullanmak önerilmez.A date related variable’s initial value is the time that it is initialized/created, therefore it is possible to read the current date just creating a date or datetime variable. But getting current date with this approach creates a vulnerability about date related bugs, so it is not recommended to use this option.
Güncel date'i almanın en güvenli ve en doğru yolu, SYS_CURRENTDATE system variable'ının değerini okumaktır. SYS_CURRENTDATE bir datetime system variable'ıdır ve her değer okumasında güncel zamanı döndürür. İşte SYS_CURRENTDATE kullanımı hakkında örnek bir kod:The safest and most correct way of getting current date is reading SYS_CURRENTDATE system variable’s value. SYS_CURRENTDATE is a datetime system variable and returns current time in each value read. Here is a sample code about using SYS_CURRENTDATE:
OBJECT:
INTEGER INTEGERVAR1,
STRING STRINGVAR3;
STRINGVAR3 = '';
INTEGERVAR1 = 0;
STRINGVAR3 = 'Data Type:' + GETVARTYPE(SYS_CURRENTDATE) + TOCHAR(10);
WHILE INTEGERVAR1 < 3
BEGIN
DELAY 1000;
STRINGVAR3 = STRINGVAR3 + SYS_CURRENTDATE + TOCHAR(10);
INTEGERVAR1 = INTEGERVAR1 + 1;
ENDWHILE;Diğer bir seçenek, güncel zamanı long değer olarak döndüren CURRENTTIMEMILLIS() system function'ını kullanmaktır. Çoğunlukla iki operation arasındaki zamanı ölçmek için kullanılsa da, güncel date'i almak için de kullanılabilir. Aşağıdaki örnek, CURRENTTIMEMILLIS() function'ının iki farklı kullanımını birleştirir.Another option is using CURRENTTIMEMILLIS() system function that returns current time as long value. Although it is mostly used to measure the time between two operations, it can be also used for getting current date. The example below combines two different usages of CURRENTTIMEMILLIS() function.
OBJECT:
LONG LONGVAR1,
DATETIME DATETIMEVAR1,
STRING STRINGVAR3;
DATETIMEVAR1 = CURRENTTIMEMILLIS();
LONGVAR1 = CURRENTTIMEMILLIS();
DELAY 1000;
LONGVAR1 = CURRENTTIMEMILLIS() - LONGVAR1;
STRINGVAR3 = DATETIMEVAR1 + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + 'It takes: '+ LONGVAR1 + ' ms.'+TOCHAR(10);Date ile İlgili Type'ları Kontrol Etme ve Validate EtmeChecking and Validating Date Related Types
Bazı durumlarda, programcıların bir variable'ın date veya datetime symbol'ü olup olmadığını bilmesi gerekir. ISDATE() system function'ı verilen variable'ı kontrol eder ve boolean bir sonuç döndürür. Aşağıdaki örnek, bu function'ın yalnızca DATE ve DATETIME data type'ları için true (1) döndürdüğünü, aksi halde variable date'e dönüştürülebilir bir string içerse bile false (0) döndürdüğünü gösterir:In some cases, programmers need to know whether a variable is a date or datetime symbol. ISDATE() system function checks given variable and returns a boolean result. The example below shows that this function returns true (1) for only DATE and DATETIME data types, otherwise it returns false (0) even variable contains a string that can be convertible to date:
OBJECT:
STRING SRINGVAR1,
DATE DATEVAR1,
DATETIME DATETIMEVAR1,
TIME TIMEVAR1,
TIMES TIMESVAR1;
STRINGVAR1 = DATETIMEVAR1;
STRINGVAR3 = '';
STRINGVAR3 = STRINGVAR3 + 'SRINGVAR1 :' + ISDATE(SRINGVAR1) + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + 'DATEVAR1 :' + ISDATE(DATEVAR1)+ TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + 'DATETIMEVAR1 :' + ISDATE(DATETIMEVAR1)+ TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + 'TIMEVAR1 :' + ISDATE(TIMEVAR1)+ TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + 'TIMESVAR1 :' + ISDATE(TIMESVAR1)+ TOCHAR(10);Bir string değerinin geçerli bir date/datetime olup olmadığını validate etmek için TROIA'nın, bir string parametresi alan ve boolean (integer) döndüren CHECKDATE() system function'ı vardır. Benzer şekilde, CHECKTIME() time/times geçerliliğini kontrol etmek için kullanılır. İşte CHECKDATE() ve CHECKTIME() function'larının davranışını gösteren örnek bir kod.To validate a string value whether it is a valid date/datetime TROIA has CHECKDATE() system function that gets a string parameter and returns boolean (integer). Similarly, CHECKTIME() is used for checking time/times validity. Here is a sample code that shows the behavior of CHECKDATE() and CHECKTIME() functions.
OBJECT:
STRING SRINGVAR1,
DATE DATEVAR1,
DATETIME DATETIMEVAR1,
TIME TIMEVAR1,
TIMES TIMESVAR1;
STRINGVAR1 = DATETIMEVAR1;
STRINGVAR3 = '';
STRINGVAR3 = STRINGVAR3 + 'SRINGVAR1 :' + CHECKDATE(STRINGVAR1) + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + '19.06.2018 :' + CHECKDATE('19.06.2018')+ TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + '35.06.2018 :' + CHECKDATE('35.06.2018')+ TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + 'DATETIMEVAR1 :' + CHECKDATE(DATETIMEVAR1)+ TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + 'TIMEVAR1 :' + CHECKTIME(TIMEVAR1)+ TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + 'TIMESVAR1 :' + CHECKTIME(TIMESVAR1)+ TOCHAR(10);Date/Datetime Variable'larından Data ÇıkarmaExtracting Data From Date/Datetime Variables
Verilen bir date variable'ının date veya time kısmını GETDATE() ve GETTIME() function'larını kullanarak almak mümkündür. Bir DATETIME variable'ını bir DATE, TIME veya TIMES variable'ına atayarak aynı kısımları almak da mümkündür. TROIA doğru kısmı otomatik olarak çıkarır, daha fazla bilgi için casting bölümüne bakınız. Aşağıdaki örnek, GETDATE() ve GETTIME() function'ının davranışını gösterir.It is possible to get date or time part of given date variable using GETDATE() and GETTIME() functions. It is also possible to get same parts assigning a DATETIME variable to a DATE, TIME or TIMES variable. TROIA automatically extracts correct part, please see the casting section for more information. The example below shows GETDATE() and GETTIME() function’s behavior.
OBJECT:
STRING SRINGVAR1,
DATETIME DATETIMEVAR1;
STRINGVAR1 = DATETIMEVAR1;
STRINGVAR3 = '';
STRINGVAR3 = STRINGVAR3 + GETDATE(STRINGVAR1) + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + GETTIME(STRINGVAR1) + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + GETDATE(DATETIMEVAR1)+ TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + GETTIME(DATETIMEVAR1)+ TOCHAR(10);Bir date'in yıl, gün veya ay gibi tek bir kısmını almak için aşağıdaki örnekteki gibi function'ları kullanmalısınız:To get a single part of a date like year, day or month you must use the functions in the like the example below:
| GETDAY() | Returns the day value of given date. |
|---|---|
| GETDAYOFWEEK() | Returns day of week. is given day monday(1), tuesday (2), wednesday (3) … |
| GETHOUR() | Returns the hour part |
| GETMINUTE() | Returns the minute part |
| GETMONTH() | Returns the month part |
| GETYEAR() | Returns the year part |
| GETWEEK() | Returns week number of given date |
OBJECT:
STRING SRINGVAR1,
DATE DATEVAR1,
DATETIME DATETIMEVAR1;
STRINGVAR1 = DATETIMEVAR1;
STRINGVAR3 = '';
STRINGVAR3 = STRINGVAR3 + GETDAYOFWEEK(STRINGVAR1) + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + GETDAYOFWEEK(DATETIMEVAR1)+ TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + GETWEEK(STRINGVAR1) + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + GETWEEK(DATETIMEVAR1)+ TOCHAR(10);Date'leri HesaplamaCalculating Dates
Bir ayın son günü sabit değildir, yılın artık yıl olup olmamasına bağlı olarak aya ve date'e bağlıdır. Bu tür hesaplamalar için TROIA'nın development çabasını kolaylaştırmak için aşağıdaki function'ları vardır.Last day of a month is not a constant, it depends on to the month and date due to whether year is a leap year. For such a kind of calculations TROIA has functions below to ease development effort.
| GETDATEFROMWEEK() | Gets week and year parameter and returns the first day of the given week as date |
|---|---|
| FIRSTDATEINMONTH() | Gets month and year parameter and returns the first day of the given month as date |
| LASTDATEINMONTH() | Gets month and year parameter and returns the last day of the given month as date |
İşte bu haftanın ilk gününü döndüren basit bir örnek:Here is a simple example that returns the fists day of this week:
OBJECT:
INTEGER THISYEAR,
INTEGER THISWEEK;
STRINGVAR3 = '';
THISYEAR = GETYEAR(SYS_CURRENTDATE);
THISWEEK = GETWEEK(SYS_CURRENTDATE);
STRINGVAR3 = GETDATEFROMWEEK(THISWEEK,THISYEAR);Ayrıca bir date'e gün, dakika vb. eklemek veya çıkarmak ve başka bir date hesaplamak da mümkündür. Bu tür operation'lar için TROIA'nın ADDDAYS(), ADDYEARS(), ADDHOURS(), ADDMINUTES(), SUBDAYS(), SUBMONTHS() gibi function'ları vardır. Tüm bu hesaplamalar timezone'u, artık yıl sorunlarını ve önceden tanımlı configuration'ı dikkate alır ve TROIA programcıları için development çabasını azaltır. Daha fazla detay ve function için lütfen TROIA Help dokümanlarına bakınız.Also is possible to add or subtract days, minutes etc. to a date and calculate another date. For this kind operations TROIA has functions like ADDDAYS(), ADDYEARS(), ADDHOURS(), ADDMINUTES(),SUBDAYS(),SUBMONTHS() etc. All this calculations takes timezone, leap year issues and predefined configuration into the account and reduces development effort for TROIA programmers. For more details and functions please see TROIA Help documents.
Date Farkını HesaplamaCalculating Date Difference
İki date arasındaki farkı gün veya dakika olarak hesaplamak için, sadece bir date'i diğerinden çıkarmalısınız. Bu operation farkı milisaniye olarak döndürür ve bu farkı gün hatta yıl olarak hesaplayabilirsiniz. Ayrıca TROIA'nın farkı dakika olarak döndüren GETMINUTEDIFF() function'ı vardır. İşte date farkını hesaplama hakkında iki farklı yaklaşımı gösteren bir örnek.To calculate difference between two dates in days or minutes, you must only subtract a date from another. This operation returns difference in milliseconds and you can calculate this difference in days or even years. Also TROIA has GETMINUTEDIFF() function that returns the difference in minutes. Here is an example that shows two different approach about calculating date difference.
OBJECT:
DATETIME DATETIMEVAR1,
DATETIME DATETIMEVAR2;
STRINGVAR3 = '';
DATETIMEVAR1 = '25.11.1984 03:00:00';
DATETIMEVAR2 = '25.11.1984 04:00:00';
LONGVAR1 = (DATETIMEVAR2 - DATETIMEVAR1) / (1000*60);
LONGVAR2 = GETMINUTEDIFF(DATETIMEVAR1, DATETIMEVAR2);NULLDATE Nedir?What is NULLDATE?
TROIA dialog'larında, DATETIME ve DATE textfield'lar boş bırakılabilir. Bu durumda bu date/datetime symbol'lerinin değeri özel bir değere ayarlanır. Bu özel değere NULLDATE denir ve date symbol'leri için string'e " . . : : " veya " . . " olarak dönüştürülür. Bu yaklaşım date/datetime column'ları olan table column'ları için de aynıdır. Verilen bir text'in NULLDATE olup olmadığını kontrol etmek için TROIA'nın boolean (integer) bir sonuç döndüren bir NULLDATE() function'ı vardır. İşte basit bir örnek:In TROIA dialogs, DATETIME and DATE text fields can be leaved as empty. In this case the value of this date/datetime symbols is set to a special value. This special value is called as NULLDATE and this value converted to string as “ . . : : “ or “ . . “ for date symbols. This approach is also same for table columns for date/datetime columns. To check whether given text is NULLDATE or not TROIA has a NULLDATE() function that returns a boolean (integer) result. Here is a simple example:
OBJECT:
STRING STRINGVAR1,
STRING STRINGVAR2,
STRING STRINGVAR3,
DATETIME DATETIMEVAR1;
DATETIMEVAR1 = '';
STRINGVAR1 = DATETIMEVAR1;
STRINGVAR2 = SYS_CURRENTDATE;
STRINGVAR3 ='';
STRINGVAR3 = STRINGVAR3 + NULLDATE(STRINGVAR1) + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + NULLDATE(STRINGVAR2) + TOCHAR(10);Min Date & Max Date KonseptleriMin Date & Max Date Concepts
Bazı durumlarda, TROIA programcılarının TROIA date'lerinin üst ve alt limitleri gibi bazı özel date değerlerine ihtiyacı olur. Bir document için bir expiration date'iniz olduğunu ve hiç expire olmayan document'lar için maksimum bir date değeri kullanmanız gerektiğini varsayın. Bu durumlar için sistem, datetime olan SYS_MINDATE ve SYS_MAXDATE system variable'larıyla minimum ve maksimum date'leri döndürür. Ayrıca ISMAXDATE() ve ISMINDATE() function'larını kullanarak bir datetime/date symbol'ünün max date/min date olup olmadığını kontrol etmek de mümkündür. TROIA code'u içinde bu hardcode date'leri kullanmak önerilmez.In some cases, TROIA programmers need some special dates values like upper and lower limits of TROIA dates. Assume that you have an expiration date for a document and in some documents you must use a maximum date value for the documents that never expire. For this cases system returns minimum and maximum dates with SYS_MINDATE and SYS_MAXDATE system variables which are datetime. Also it is possible to check whether a datetime/date symbol is max date/min date or not using ISMAXDATE() and ISMINDATE() functions. It is not recommended that using these hard coded dates inside TROIA code.
OBJECT:
STRING STRINGVAR3;
STRINGVAR3 = ISMINDATE(SYS_MINDATE) + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + ISMINDATE(SYS_CURRENTDATE)+ TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + ISMAXDATE(SYS_MAXDATE)+ TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + ISMAXDATE(SYS_CURRENTDATE)+ TOCHAR(10);3.08.x sürümlerinde varsayılan olarak, bu max date ve min date değerleri 01.01.1975 00:00:00 ve 01.01.2030 00:00:00'dır ve hardcode'dur. 5.01 sürümlerinden sonra bu maksimum ve minimum yılları bir database için configure etmek mümkündür. Min ve max yılı configure etmek için IASSYSTEM table'ının MINDATEYEAR ve MAXDATEYEAR column'larını ayarlamanız gerekir. Bu parametreler configure edilebilir olsa da, planlı bir migration olmadan database table'ları üzerinde bu değerleri değiştirmek önerilmez.In 3.08.x versions as default, this max date and min date values are 01.01.1975 00:00:00 and 01.01.2030 00:00:00 and they are hard coded. After 5.01 versions it is possible to configure these maximum and minimum years for a database. To configure min and max year you have to set MINDATEYEAR and MAXDATEYEAR columns of IASSYSTEM table. Although this parameters are configurable, it is not recommended to change this values without a planned migration over database tables.
Basic Date Formatting/ParsingBasic Date Formatting/Parsing
Date formatting, bir date/datetime variable'ını DD.MM.YYYY veya YYYY.MM.DD gibi bir format kullanarak string'e dönüştürmek anlamına gelir. Ve parsing, bir string'den date değerini çıkarmaktır. Date formatı nedeniyle, hem formatting hem parsing operation'ları için ortaya çıkan değer farklı olabilir.Date formatting means converting a date/datetime variable to a string using a format like DD.MM.YYYY or YYYY.MM.DD etc. And parsing is extracting date value from a string. Due to date format resulting value can be different for both formatting and parsing operations.
Varsayılan olarak, bir date/datetime variable'ı bir string variable'a atanırsa sistem 'DD.MM.YYYY'/'DD.MM.YYYY HH:MM:SS' formatını kullanır. Bir date formatı sağlamadan date'leri parse etmek için de aynı format geçerlidir. Bu yüzden tüm hardcode date'ler bu format kullanılarak verilmelidir. Lütfen aşağıdaki koda bakın ve davranışı tartışın:As default, if a date/datetime variable is assigned to a string variable system uses ‘DD.MM.YYYY’/’DD.MM.YYYY HH:MM:SS’ format. Same format is valid for parsing dates without providing a date format. So all hardcode dates must be given using this format. Please see the code below and discuss the behavior:
OBJECT:
STRING STRINGVAR3,
DATETIME DATETIMEVAR1,
DATETIME DATETIMEVAR2;
DATETIMEVAR1 = '30.12.2018 21:41:42';
DATETIMEVAR2 = '2018.12.30 21:41:42';
STRINGVAR3 = DATETIMEVAR1;Bu, decimal'lerle tamamen aynıdır, tüm programcılar TROIA code'u içinde decimal separator olarak . (nokta) kullanır. Hardcode'dur ve dilden veya herhangi bir localization configuration'ından bağımsızdırThis is totally same with decimals, all programmers uses . (dot) as decimal separator inside TROIA code. It is hard coded and independent from language or any localization configuration
Formatting Configuration'ları & İlgili System Variable'larFormatting Configurations & Related System Variables
Troia'da, text field değerleri veya table cell'leri için date/datetime değerlerini formatlamaya gerek yoktur. Bu field'lar, IDE'de hardcode özel bir formatı yoksa otomatik olarak formatlanır. Control'ler ve table field'larının default formatları kullanması için aşağıdaki format text'lerini kullanmalısınız:In troia, there is no need to format date/datetime values for text field values or table cells. This fields are formatted automatically if they has not a hard coded special format given on IDE. For controls and table fields to use default formats you must use format texts below:
| datetime | use default datetime format |
|---|---|
| datetimes | use default datetime format that contains second |
| date | use default date format |
| time | use default time format |
| times | use default time format that contains second |
Bu yüzden bir DATETIME textfield'ı bu format parametrelerini kullanarak default date formatıyla göstermek mümkündür. Ayrıca, textfield'ları ve table column'larını, java tarafından desteklenen "yy.MM.dd" gibi bir date formatı kullanarak user date format configuration'ından bağımsız olarak configure etmek de mümkündür.So it is possible to show a DATETIME text field with default date format using this format parameters. Additionally it is possible to configure text fields and table columns independent from user date format configuration using a date format supported by java like “yy.MM.dd”.
Sistem, "SYST03 - System Users" transaction'ındaki date formatting configuration'ını kullanarak tüm date ile ilgili data type'ları için default formatları hesaplar ve default formatlanmış textfield'lar ve table cell'leri için kullanır. Ayrıca, default date formatlarını kullanan custom text'leri formatlamak için aşağıda listelenen system variable'ları kullanarak TROIA'dan tüm bu formatlara erişilebilir.System calculates default formats for all date related data types using the date formatting configuration on “SYST03 - System Users” transaction and uses for default formatted text fields and table cells. Also, all this formats can be accessed from TROIA using system variables listed below to format custom texts that uses default date formats.
| SYS_DATETIMEFORMAT | Default datetime format |
|---|---|
| SYS_DATETIMESFORMAT | Default datetime format that contains second |
| SYS_DATEFORMAT | Default date format |
| SYS_TIMEFORMAT | Default time format |
| SYS_TIMESFORMAT | Default time format that contains second |
OBJECT:
STRING STRINGVAR3;
STRINGVAR3 = '';
STRINGVAR3 = STRINGVAR3 + SYS_DATETIMEFORMAT + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + SYS_DATETIMESFORMAT + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + SYS_DATEFORMAT + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + SYS_TIMEFORMAT + TOCHAR(10);
STRINGVAR3 = STRINGVAR3 + SYS_TIMESFORMAT + TOCHAR(10);Bu system variable'ları 5.02.05 ve sonraki sürümlerden sonra desteklenir, bu yüzden bu variable'ları 3.08.x ve 5.01.x sürümlerinde kullanmak mümkün değildir.This system variables are supported after 5.02.05 and following versions, so it is not possible to use this variables on 3.08.x and 5.01.x versions.
TROIA ile Date Formatting & ParsingDate Formatting & Parsing Dates with TROIA
FORMATDATE() ve PARSEDATE() function'ları sayesinde, default formatları veya farklı hardcode formatları kullanarak date ile ilgili type'ları parse etmek ve formatlamak mümkündür.It is possible to parse and format date related types using default formats or different hard codded formats thanks to FORMATDATE() and PARSEDATE() functions.
FORMATDATE() function'ı bir date ve format alır, verilen formata göre bir string döndürür. İşte bir örnek:FORMATDATE() function gets a date and format, returns a string due to given format. Here is an examples:
OBJECT:
STRING NLN,
STRING STRINGVAR3;
NLN = TOCHAR(10);
STRINGVAR3 = '';
STRINGVAR3 = STRINGVAR3 + FORMATDATE(SYS_CURRENTDATE, 'yyyy.MM.dd') + NLN;
STRINGVAR3 = STRINGVAR3 + FORMATDATE(SYS_CURRENTDATE, SYS_DATETIMEFORMAT) + NLN;
STRINGVAR3 = STRINGVAR3 + FORMATDATE(SYS_CURRENTDATE, SYS_TIMESFORMAT)+ NLN;PARSEDATE() function'ı bir string variable ve format alır, bir datetime variable döndürür. İşte bir örnek:PARSEDATE() function gets a string variable and format, returns and datetime variable. Here is an example:
OBJECT:
STRING NLN,
STRING STRINGVAR3;
NLN = TOCHAR(10);
STRINGVAR3 = '';
STRINGVAR3 = STRINGVAR3 + PARSEDATE('2018.06.19', 'yyyy.MM.dd') + NLN;
STRINGVAR3 = STRINGVAR3 + PARSEDATE('19.06.2018 17:25', SYS_DATETIMEFORMAT) + NLN;
STRINGVAR3 = STRINGVAR3 + PARSEDATE('17:25:54', SYS_TIMESFORMAT)+ NLN;Bu system function'ları 5.02.05 ve sonraki sürümlerden sonra desteklenir, bu yüzden bu variable'ları 3.08.x ve 5.01.x sürümlerinde kullanmak mümkün değildir.This system functions are supported after 5.02.05 and following versions, so it is not possible to use this variables on 3.08.x and 5.01.x versions.
Database & Date FormatDatabase & Date Format
Date format'ları her kullanıcı için configure edilebilir, ama database katmanında yalnızca bir date/datetime format kullanılır. Bu format, "SYST06 - System Parameters" transaction'ının Database bölümünde configure edilir. Sistem, herhangi bir TROIA seviyesi çaba olmadan database etkileşimleri için date ile ilgili variable'ları ve table cell'lerini otomatik olarak formatlar.Date formats can be configured for each user, but on database layer only one date/datetime format is used. This format is configured on Database section of “SYST06 - System Parameters” transaction. System automatically formats date related variables and table cells for database interactions without any TROIA level effort.
Database date formatını kullanarak bir date/datetime variable'ını formatlamak için GETDBDATESTR() function'ını kullanmalısınız. GETDBDATESTR() function'ı çoğunlukla hardcode date/datetime değerleri içeren database query'leri hazırlamak için kullanılır. Lütfen aşağıdaki kodu çalıştırın ve sonucu database date format configuration'ınızla karşılaştırın.To format a date/datetime variable using database date format you must use GETDBDATESTR() function. GETDBDATESTR() function is mostly used for preparing database queries that contains hardcode date/datetime values. Please run the code below and compare the result with your database date format configuration.
OBJECT:
STRING STRINGVAR3;
STRINGVAR3 = GETDBDATESTR(SYS_CURRENTDATE);TimezoneTimezone
TROIA Platformu, herhangi bir programlama çabası olmadan user configuration'ı sayesinde datetime data'sını belirli bir timezone'da gösterebilir/sunabilir. Bu configuration kullanıcı bazlıdır, bu yüzden her kullanıcı datetime textfield'ları, table cell'leri veya report'lar gibi presentation katmanında kendi timezone'unu kullanır. Kullanıcı bazlı timezone configuration'ı "SYST03 - System Users" transaction'ı tarafından ele alınır. Belirli bir timezone configuration'ı olmayan kullanıcılar, "SYST06 - System Parameters" transaction'ının System Dates bölümünde ayarlanan sistemin default configuration'ını kullanır.TROIA Platform, is able to show/present datetime data in a specific timezone due to user configuration without any programming effort. This configuration is based on users, so each users uses its own timezone on presentation layer like datetime text fields, table cells or reports. User based timezone configuration is handled by “SYST03 - System Users” transaction. Users that has not a specific timezone configuration users system’s default configuration which is set on System Dates section of “SYST06 - System Parameters” transaction.
Date'ler user interface katmanında kullanıcıların timezone'unda sunulsa da, sistem date'leri standart bir timezone'da saklar, bu configuration'a "Database Timezone" denir ve "SYST06 - System Parameters" transaction'ının Database bölümünde configure edilir. Database transaction configure edilebilir olsa da, tüm date'lerin timezone'unu sakladığı için planlı bir data migration olmadan bu configuration'ı değiştirmek önerilmezAlthough dates are presented on users’ timezone on user interface layer, system stores dates in a standard timezone, this configuration is called as “Database Timezone” and it is configured on Database section of “SYST06 - System Parameters” transaction. Although database transaction configurable, it is not recommended to change this configuration without a planned data migration, because it stores the timezone of all dates
Timezone bilgisi data integrity nedeniyle hassas bir bilgidir, bu yüzden sistem kullanıcı, sistem veya client cihazlarının timezone'u hakkında bazı çelişkiler algılarsa bazı warning mesajları oluşturur. Bu mesajlar, server settings dosyasındaki IgnoreTimezoneWarnings parametresi kullanılarak devre dışı bırakılabilir, default değeri "false"tur, bu yüzden timezone warning'leri açıktır; "true" olarak ayarlarsanız bu warning'leri kapatır.Timezone information is a sensitive information because of data integrity, so if system senses some conflictions about user, system or client devices’ timezone creates some warning messages. This messages can be disabled using IgnoreTimezoneWarnings parameter on server settings file, its default value is “false”, so timezone warnings are on, if you set it to “true” this will turn warnings off.
Work CalendarWork Calendar
TROIA'da, bazı business katmanı calendar'ları tanımlamak ve bu calendar'ların kısıtlamalarını dikkate alarak gün, saat vb. ekleme gibi bazı date hesaplamaları yapmak da mümkündür. Bu tür date hesaplamalarına "Work Calendar" denir, Work Calendar'ları ilerleyen bölümlerde ele alacağız.In TROIA, it is also possible to define some business layer calendars and make some date calculations like adding days, hours etc. considering constraints of this calendars. This kind of date calculations are called “Work Calendar”, we will discuss Work Calendars in following sections.